Skip to content

Commit

Permalink
fix ignore send data to sls issue
Browse files Browse the repository at this point in the history
  • Loading branch information
xujinzheng committed Dec 21, 2018
1 parent 511605b commit ceff793
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions hooks/sls/sls.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (p *SLSHook) Levels() []logrus.Level {
return p.AcceptedLevels
}

// Fire - Sent event to slack
// Fire - Sent event to sls
func (p *SLSHook) Fire(entry *logrus.Entry) (err error) {

storeName := p.Config.Store
Expand All @@ -140,7 +140,9 @@ func (p *SLSHook) Fire(entry *logrus.Entry) (err error) {
store, _ = p.mapStores.LoadOrStore(storeName, newStore)
}

delete(entry.Data, p.Config.Store)
ignoreToSend := map[string]bool{}

ignoreToSend[p.Config.Store] = true

logStore, ok := store.(*sls.LogStore)
if !ok {
Expand All @@ -166,7 +168,7 @@ func (p *SLSHook) Fire(entry *logrus.Entry) (err error) {
strCtx = string(jsonData)
}

delete(entry.Data, p.Config.ContextField)
ignoreToSend[p.Config.ContextField] = true

slsLog.Contents = append(slsLog.Contents,
&sls.LogContent{
Expand All @@ -180,12 +182,16 @@ func (p *SLSHook) Fire(entry *logrus.Entry) (err error) {
topic := proto.String(fieldToString(entry, p.Config.TopicField))
source := proto.String(fieldToString(entry, p.Config.SourceField))

delete(entry.Data, p.Config.TopicField)
delete(entry.Data, p.Config.SourceField)
ignoreToSend[p.Config.TopicField] = true
ignoreToSend[p.Config.SourceField] = true

if len(entry.Data) > 0 {
for k, v := range entry.Data {

if ignoreToSend[k] {
continue
}

content := &sls.LogContent{
Key: proto.String(k),
Value: proto.String(fmt.Sprintf("%v", v)),
Expand Down

0 comments on commit ceff793

Please sign in to comment.