fix race condition for SetFormatter and properly fix SetReportCaller race as well

This commit is contained in:
Ruben de Vries
2021-06-16 11:54:39 +02:00
parent b50299cfaa
commit 78f838918d
2 changed files with 25 additions and 2 deletions
+2 -2
View File
@@ -284,13 +284,13 @@ func (entry *Entry) fireHooks() {
}
func (entry *Entry) write() {
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
serialized, err := entry.Logger.Formatter.Format(entry)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err)
return
}
entry.Logger.mu.Lock()
defer entry.Logger.mu.Unlock()
if _, err := entry.Logger.Out.Write(serialized); err != nil {
fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err)
}