diff --git a/entry.go b/entry.go index 1bf127c..c6da562 100644 --- a/entry.go +++ b/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() diff --git a/entry_test.go b/entry_test.go index 423e5ed..30eddae 100644 --- a/entry_test.go +++ b/entry_test.go @@ -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") + }() +}