Merge pull request #1116 from admacleod/master

Resolve race condition with SetReportCaller() and Entry
This commit is contained in:
Mark Phelps 2020-03-22 09:24:01 -04:00 committed by GitHub
commit 4ddc9cf62e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -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()

View File

@ -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")
}()
}