Update signature of WriteMsg in es.go

This commit is contained in:
IamCathal 2020-08-19 16:13:42 +01:00
parent ca4a217783
commit ff5ac3adf4
2 changed files with 9 additions and 9 deletions

View File

@ -113,7 +113,7 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
if c.withMap {
// TopicLogGroup
strs := strings.SplitN(msg, Delimiter, 2)
strs := strings.SplitN(lm.Msg, Delimiter, 2)
if len(strs) == 2 {
pos := strings.LastIndex(strs[0], " ")
topic = strs[0][pos+1 : len(strs[0])]
@ -123,11 +123,11 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
// send to empty Topic
if lg == nil {
content = msg
content = lm.Msg
lg = c.group[0]
}
} else {
content = msg
content = lm.Msg
lg = c.group[0]
}
@ -137,7 +137,7 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
}
l := &Log{
Time: proto.Uint32(uint32(when.Unix())),
Time: proto.Uint32(uint32(lm.When.Unix())),
Contents: []*LogContent{
c1,
},

View File

@ -60,14 +60,14 @@ func (el *esLogger) Init(jsonconfig string) error {
}
// WriteMsg writes the msg and level into es
func (el *esLogger) WriteMsg(when time.Time, msg string, level int) error {
if level > el.Level {
func (el *esLogger) WriteMsg(lm *logs.LogMsg) error {
if lm.Level > el.Level {
return nil
}
idx := LogDocument{
Timestamp: when.Format(time.RFC3339),
Msg: msg,
Timestamp: lm.When.Format(time.RFC3339),
Msg: lm.Msg,
}
body, err := json.Marshal(idx)
@ -75,7 +75,7 @@ func (el *esLogger) WriteMsg(when time.Time, msg string, level int) error {
return err
}
req := esapi.IndexRequest{
Index: fmt.Sprintf("%04d.%02d.%02d", when.Year(), when.Month(), when.Day()),
Index: fmt.Sprintf("%04d.%02d.%02d", lm.When.Year(), lm.When.Month(), lm.When.Day()),
DocumentType: "logs",
Body: strings.NewReader(string(body)),
}