forked from mirror/logrus
Merge pull request #1116 from admacleod/master
Resolve race condition with SetReportCaller() and Entry
This commit is contained in:
commit
4ddc9cf62e
2
entry.go
2
entry.go
|
@ -232,9 +232,11 @@ func (entry Entry) log(level Level, msg string) {
|
|||
|
||||
entry.Level = level
|
||||
entry.Message = msg
|
||||
entry.Logger.mu.Lock()
|
||||
if entry.Logger.ReportCaller {
|
||||
entry.Caller = getCaller()
|
||||
}
|
||||
entry.Logger.mu.Unlock()
|
||||
|
||||
entry.fireHooks()
|
||||
|
||||
|
|
|
@ -243,3 +243,14 @@ func TestEntryLogfLevel(t *testing.T) {
|
|||
entry.Logf(WarnLevel, "%s", "warn")
|
||||
assert.Contains(t, buffer.String(), "warn")
|
||||
}
|
||||
|
||||
func TestEntryReportCallerRace(t *testing.T) {
|
||||
logger := New()
|
||||
entry := NewEntry(logger)
|
||||
go func() {
|
||||
logger.SetReportCaller(true)
|
||||
}()
|
||||
go func() {
|
||||
entry.Info("should not race")
|
||||
}()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue