From ba670baee189f68debc2d23e69b848d46436916a Mon Sep 17 00:00:00 2001 From: Alisdair MacLeod Date: Thu, 19 Mar 2020 10:01:29 +0000 Subject: [PATCH] fix deadlock in previous entry race condition fix --- entry.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/entry.go b/entry.go index 3928671..5082cfa 100644 --- a/entry.go +++ b/entry.go @@ -219,8 +219,7 @@ func (entry Entry) HasCaller() (has bool) { // This function is not declared with a pointer value because otherwise // race conditions will occur when using multiple goroutines func (entry Entry) log(level Level, msg string) { - entry.Logger.mu.Lock() - defer entry.Logger.mu.Unlock() + var buffer *bytes.Buffer // Default to now, but allow users to override if they want. @@ -234,9 +233,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()