Merge pull request #65 from pquerna/remove_unused_string

Only convert []bytes into a String() when needed for a panic
This commit is contained in:
Simon Eskildsen 2014-09-24 23:06:38 -04:00
commit 51ca046ebf
1 changed files with 5 additions and 4 deletions

View File

@ -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\n", 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...))
}