Skip to content

Commit

Permalink
Merge pull request sirupsen#1116 from admacleod/master
Browse files Browse the repository at this point in the history
Resolve race condition with SetReportCaller() and Entry
  • Loading branch information
markphelps committed Mar 22, 2020
2 parents 6f5e581 + c419666 commit f4b38d3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions entry.go
Expand Up @@ -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()

Expand Down
11 changes: 11 additions & 0 deletions entry_test.go
Expand Up @@ -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")
}()
}

0 comments on commit f4b38d3

Please sign in to comment.