diff --git a/entry.go b/entry.go index 263b005..5c971f6 100644 --- a/entry.go +++ b/entry.go @@ -122,6 +122,8 @@ func (entry *Entry) WithField(key string, value interface{}) *Entry { // Add a map of fields to the Entry. func (entry *Entry) WithFields(fields Fields) *Entry { + entry.Logger.mu.Lock() + defer entry.Logger.mu.Unlock() data := make(Fields, len(entry.Data)+len(fields)) for k, v := range entry.Data { data[k] = v diff --git a/entry_test.go b/entry_test.go index 973091e..423e5ed 100644 --- a/entry_test.go +++ b/entry_test.go @@ -210,7 +210,7 @@ func TestEntryWithIncorrectField(t *testing.T) { fn := func() {} - e := Entry{} + e := &Entry{Logger: New()} eWithFunc := e.WithFields(Fields{"func": fn}) eWithFuncPtr := e.WithFields(Fields{"funcPtr": &fn}) @@ -238,8 +238,8 @@ func TestEntryLogfLevel(t *testing.T) { entry := NewEntry(logger) entry.Logf(DebugLevel, "%s", "debug") - assert.NotContains(t, buffer.String(), "debug", ) + assert.NotContains(t, buffer.String(), "debug") entry.Logf(WarnLevel, "%s", "warn") - assert.Contains(t, buffer.String(), "warn", ) -} \ No newline at end of file + assert.Contains(t, buffer.String(), "warn") +}