1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-24 16:10:55 +00:00

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

View File

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