Ver código fonte

Slightly improve panic log format (...)

 - Don't repeat the first log lines
 - Print panic timestamp in context.
Jakob Borg 11 anos atrás
pai
commit
e9d27b9d2b
1 arquivos alterados com 7 adições e 5 exclusões
  1. 7 5
      cmd/syncthing/monitor.go

+ 7 - 5
cmd/syncthing/monitor.go

@@ -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)