Slightly improve panic log format (...)

- Don't repeat the first log lines
 - Print panic timestamp in context.
This commit is contained in:
Jakob Borg 2014-10-09 09:29:29 +02:00
parent 828bbc407f
commit e9d27b9d2b

View File

@ -153,7 +153,6 @@ func copyStderr(stderr io.ReadCloser) {
l.Warnf("Panic detected, writing to \"%s\"", panicFd.Name())
l.Warnln("Please create an issue at https://github.com/syncthing/syncthing/issues/ with the panic log attached")
panicFd.WriteString("Panic at " + time.Now().Format(time.RFC1123) + "\n")
stdoutMut.Lock()
for _, line := range stdoutFirstLines {
panicFd.WriteString(line)
@ -163,6 +162,8 @@ func copyStderr(stderr io.ReadCloser) {
panicFd.WriteString(line)
}
}
panicFd.WriteString("Panic at " + time.Now().Format(time.RFC3339) + "\n")
}
if panicFd != nil {
@ -182,11 +183,12 @@ func copyStdout(stderr io.ReadCloser) {
stdoutMut.Lock()
if len(stdoutFirstLines) < cap(stdoutFirstLines) {
stdoutFirstLines = append(stdoutFirstLines, line)
} else {
if l := len(stdoutLastLines); l == cap(stdoutLastLines) {
stdoutLastLines = stdoutLastLines[:l-1]
}
stdoutLastLines = append(stdoutLastLines, line)
}
if l := len(stdoutLastLines); l == cap(stdoutLastLines) {
stdoutLastLines = stdoutLastLines[:l-1]
}
stdoutLastLines = append(stdoutLastLines, line)
stdoutMut.Unlock()
os.Stdout.WriteString(line)