Saving off entry string for use in panic

as the reader is not seekable and without this the panic string is
always empty 🙀
This commit is contained in:
Dan Buch
2014-11-05 13:49:58 -05:00
parent 6ebb4e7b3c
commit ced531341e
2 changed files with 19 additions and 5 deletions
+5 -2
View File
@@ -88,10 +88,13 @@ 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, 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 @@ func (entry *Entry) log(level Level, msg string) {
// panic() to use in Entry#Panic(), we avoid the allocation by checking
// directly here.
if level <= PanicLevel {
panic(reader.String())
panic(panicBuf.String())
}
}