forked from mirror/logrus
fix ReportCaller race condition
This commit is contained in:
parent
c9b4f5af6d
commit
b9d451406d
2
entry.go
2
entry.go
|
@ -206,7 +206,9 @@ func (entry Entry) log(level Level, msg string) {
|
||||||
entry.Level = level
|
entry.Level = level
|
||||||
entry.Message = msg
|
entry.Message = msg
|
||||||
if entry.Logger.ReportCaller {
|
if entry.Logger.ReportCaller {
|
||||||
|
entry.Logger.mu.Lock()
|
||||||
entry.Caller = getCaller()
|
entry.Caller = getCaller()
|
||||||
|
entry.Logger.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.fireHooks()
|
entry.fireHooks()
|
||||||
|
|
|
@ -743,3 +743,20 @@ func TestReportCallerOnTextFormatter(t *testing.T) {
|
||||||
l.Formatter.(*TextFormatter).DisableColors = true
|
l.Formatter.(*TextFormatter).DisableColors = true
|
||||||
l.WithFields(Fields{"func": "func", "file": "file"}).Info("test")
|
l.WithFields(Fields{"func": "func", "file": "file"}).Info("test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetReportCallerRace(t *testing.T) {
|
||||||
|
l := New()
|
||||||
|
l.Out = ioutil.Discard
|
||||||
|
l.SetReportCaller(true)
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(100)
|
||||||
|
|
||||||
|
for i := 0; i < 100; i++ {
|
||||||
|
go func() {
|
||||||
|
l.Error("Some Error")
|
||||||
|
wg.Done()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue