From f302a46d2ab1439e88e51192fa8a4abfe511293d Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 5 Nov 2014 14:07:40 -0500 Subject: [PATCH] Switching to io.MultiWriter for clarity --- entry.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/entry.go b/entry.go index dc639b3..80638f3 100644 --- a/entry.go +++ b/entry.go @@ -71,6 +71,8 @@ func (entry *Entry) WithFields(fields Fields) *Entry { } func (entry *Entry) log(level Level, msg string) { + var panicBuf bytes.Buffer + entry.Time = time.Now() entry.Level = level entry.Message = msg @@ -88,13 +90,10 @@ func (entry *Entry) log(level Level, msg string) { entry.Logger.mu.Unlock() } - var panicBuf bytes.Buffer - teeOut := io.TeeReader(reader, &panicBuf) - entry.Logger.mu.Lock() defer entry.Logger.mu.Unlock() - _, err = io.Copy(entry.Logger.Out, teeOut) + _, err = io.Copy(io.MultiWriter(entry.Logger.Out, &panicBuf), reader) if err != nil { fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) }