make logx#getWriter concurrency-safe (#2233)

* make logx#getWriter concurrency-safe

* make logx#getWriter concurrency-safe
master
Archer 2 years ago committed by GitHub
parent 9d6c8f67f5
commit 8c72136631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

Loading…
Cancel
Save