diff --git a/core/logx/logs.go b/core/logx/logs.go index 76e75571..9af80757 100644 --- a/core/logx/logs.go +++ b/core/logx/logs.go @@ -358,10 +358,19 @@ func errorTextSync(msg string) { } func getWriter() Writer { - w := writer.Load() + var w Writer + + writer.lock.RLock() + w = writer.writer + writer.lock.RUnlock() + if w == nil { - w = newConsoleWriter() - writer.Store(w) + writer.lock.Lock() + if writer.writer == nil { + writer.writer = newConsoleWriter() + } + w = writer.writer + writer.lock.Unlock() } return w