add mutex on entry, not logging the global mutex

This commit is contained in:
Mark Phelps 2020-04-16 09:20:41 -04:00
parent d417be0fe6
commit cc70782477
1 changed files with 4 additions and 2 deletions

View File

@ -75,6 +75,8 @@ type Entry struct {
// err may contain a field formatting error // err may contain a field formatting error
err string err string
mu sync.Mutex
} }
func NewEntry(logger *Logger) *Entry { func NewEntry(logger *Logger) *Entry {
@ -122,8 +124,8 @@ func (entry *Entry) WithField(key string, value interface{}) *Entry {
// Add a map of fields to the Entry. // Add a map of fields to the Entry.
func (entry *Entry) WithFields(fields Fields) *Entry { func (entry *Entry) WithFields(fields Fields) *Entry {
entry.Logger.mu.Lock() entry.mu.Lock()
defer entry.Logger.mu.Unlock() defer entry.mu.Unlock()
data := make(Fields, len(entry.Data)+len(fields)) data := make(Fields, len(entry.Data)+len(fields))
for k, v := range entry.Data { for k, v := range entry.Data {
data[k] = v data[k] = v