Saving off entry string for use in panic as the reader is not seekable and without this the panic string is always empty :scream_cat:
diff --git a/entry.go b/entry.go index a77c4b0..dc639b3 100644 --- a/entry.go +++ b/entry.go
@@ -88,10 +88,13 @@ 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, reader) + _, err = io.Copy(entry.Logger.Out, teeOut) if err != nil { fmt.Fprintf(os.Stderr, "Failed to write to log, %v\n", err) } @@ -100,7 +103,7 @@ // panic() to use in Entry#Panic(), we avoid the allocation by checking // directly here. if level <= PanicLevel { - panic(reader.String()) + panic(panicBuf.String()) } }
diff --git a/examples/basic/basic.go b/examples/basic/basic.go index 3594550..a62ba45 100644 --- a/examples/basic/basic.go +++ b/examples/basic/basic.go
@@ -12,6 +12,17 @@ } func main() { + defer func() { + err := recover() + if err != nil { + log.WithFields(logrus.Fields{ + "omg": true, + "err": err, + "number": 100, + }).Fatal("The ice breaks!") + } + }() + log.WithFields(logrus.Fields{ "animal": "walrus", "size": 10, @@ -23,7 +34,7 @@ }).Warn("The group's number increased tremendously!") log.WithFields(logrus.Fields{ - "omg": true, - "number": 100, - }).Fatal("The ice breaks!") + "animal": "orca", + "size": 9009, + }).Panic("It's over 9000!") }