From f96066e3bf3d336a86255321d5436a30265c31f8 Mon Sep 17 00:00:00 2001 From: Paul Querna Date: Tue, 23 Sep 2014 17:05:07 -0700 Subject: [PATCH] Only convert []bytes into a String() when needed for a panic, and not on other log levels --- entry.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/entry.go b/entry.go index 58eb263..3f19c3b 100644 --- a/entry.go +++ b/entry.go @@ -70,7 +70,7 @@ func (entry *Entry) WithFields(fields Fields) *Entry { return &Entry{Logger: entry.Logger, Data: data} } -func (entry *Entry) log(level Level, msg string) string { +func (entry *Entry) log(level Level, msg string) { entry.Time = time.Now() entry.Level = level entry.Message = msg @@ -92,7 +92,9 @@ func (entry *Entry) log(level Level, msg string) string { fmt.Fprintf(os.Stderr, "Failed to write to log, %v", err) } - return reader.String() + if level <= PanicLevel { + panic(reader.String()) + } } func (entry *Entry) Debug(args ...interface{}) { @@ -132,8 +134,7 @@ func (entry *Entry) Fatal(args ...interface{}) { func (entry *Entry) Panic(args ...interface{}) { if entry.Logger.Level >= PanicLevel { - msg := entry.log(PanicLevel, fmt.Sprint(args...)) - panic(msg) + entry.log(PanicLevel, fmt.Sprint(args...)) } panic(fmt.Sprint(args...)) }