From 396f8eefaa6f899b05717791043b2b02ba768bd5 Mon Sep 17 00:00:00 2001 From: Marcos Lilljedahl Date: Thu, 6 Aug 2015 21:00:57 -0300 Subject: [PATCH] Make log method receive a copy of Entry structure to avoid race conditions Fixes #216 Signed-off-by: Marcos Lilljedahl --- entry.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entry.go b/entry.go index 699ea03..8a522f0 100644 --- a/entry.go +++ b/entry.go @@ -70,12 +70,12 @@ func (entry *Entry) WithFields(fields Fields) *Entry { return &Entry{Logger: entry.Logger, Data: data} } -func (entry *Entry) log(level Level, msg string) { +func (entry Entry) log(level Level, msg string) { entry.Time = time.Now() entry.Level = level entry.Message = msg - if err := entry.Logger.Hooks.Fire(level, entry); err != nil { + if err := entry.Logger.Hooks.Fire(level, &entry); err != nil { entry.Logger.mu.Lock() fmt.Fprintf(os.Stderr, "Failed to fire hook: %v\n", err) entry.Logger.mu.Unlock()