From 938dffa0e0fb6dea8e1b1900a07df3455c64c12a Mon Sep 17 00:00:00 2001 From: Antoine Grondin Date: Tue, 21 Oct 2014 19:26:29 -0400 Subject: [PATCH] hooks: lock on the logger before printing to stderr, printf args --- entry.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/entry.go b/entry.go index 9b1af6b..a77c4b0 100644 --- a/entry.go +++ b/entry.go @@ -76,12 +76,16 @@ func (entry *Entry) log(level Level, msg string) { entry.Message = msg if err := entry.Logger.Hooks.Fire(level, entry); err != nil { - fmt.Fprintf(os.Stderr, "Failed to fire hook\n", err) + entry.Logger.mu.Lock() + fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) + entry.Logger.mu.Unlock() } reader, err := entry.Reader() if err != nil { + entry.Logger.mu.Lock() fmt.Fprintf(os.Stderr, "Failed to obtain reader, %v\n", err) + entry.Logger.mu.Unlock() } entry.Logger.mu.Lock()