Fixing multi-thread problem in common/log/forwarder.go
@@ -116,24 +116,25 @@ func (h *HookWrapper) Levels() []logrus.Level {
}
func (h *HookWrapper) Fire(e *logrus.Entry) error {
+ d := e.Data
+ defer func() {
+ e.Data = d
+ }()
+ e.Data = make(map[string]interface{}, len(d)+2)
+ for k, v := range d {
+ e.Data[k] = v
+ }
+
e.Data["logtime"] = e.Time.UnixNano()
- var hasModule, hasSource bool
+ var hasModule bool
if e.Caller != nil {
if _, hasModule = e.Data[FieldKeyModule]; !hasModule {
e.Data[FieldKeyModule] = getPackageName(e.Caller.Function)
}
e.Data["src"] = fmt.Sprintf("%s:%d", path.Base(e.Caller.File), e.Caller.Line)
- hasSource = true
}
err := h.h.Fire(e)
- delete(e.Data, "logtime")
- if !hasModule {
- delete(e.Data, FieldKeyModule)
- }
- if hasSource {
- delete(e.Data, "src")
- }
return err
}
