fix: thread-safe in getWriter of logx (#2319)

This commit is contained in:
Kevin Wan
2022-08-29 08:32:17 +08:00
committed by GitHub
parent 8c72136631
commit dfeef5e497
2 changed files with 13 additions and 12 deletions

View File

@@ -358,19 +358,9 @@ func errorTextSync(msg string) {
}
func getWriter() Writer {
var w Writer
writer.lock.RLock()
w = writer.writer
writer.lock.RUnlock()
w := writer.Load()
if w == nil {
writer.lock.Lock()
if writer.writer == nil {
writer.writer = newConsoleWriter()
}
w = writer.writer
writer.lock.Unlock()
w = writer.StoreIfNil(newConsoleWriter())
}
return w