detached d17a46f

fix(logging): keep crash reports and rotate stall dumps

Queued log entries are lost on a fatal crash, so the runtime crash
report (panic and every stack) now also goes to <run>.crash next to the
run log. Crash reports and watchdog stall dumps rotate with the runs.
commit
d17a46fe3f3baf6c0263e2587c42b63528d9e4f4
author
brice · · 2026-10-10 14:44 UTC
committer
brice · · 2026-10-10 15:39 UTC
parent
6558c1f
signature
GPG VerifiedCD88F9E564E0102646FB6077A1A07C7C7C3E349D · arch-gpg Verified for the committer email
1 file · +15 -5
M internal/adapters/logging/logging.go +15 -5
@@ -7,6 +7,7 @@ import (
77 "io"
88 "os"
99 "path/filepath"
10+ runtimedebug "runtime/debug"
1011 "sort"
1112 "strings"
1213 "time"
@@ -89,6 +90,12 @@ func Open(ctx context.Context, backend, level, debug string) (context.Context, f
8990 return nil, nil, err
9091 }
9192 pruneRuns(dir)
93+ // Queued entries are lost on a fatal crash: the runtime's own report
94+ // (panic and every stack) goes to its own file, besides stderr.
95+ if crash, err := os.OpenFile(filepath.Join(dir, strings.TrimSuffix(name, ".log")+".crash"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600); err == nil {
96+ _ = runtimedebug.SetCrashOutput(crash, runtimedebug.CrashOptions{})
97+ _ = crash.Close() // SetCrashOutput keeps its own duplicate
98+ }
9299 // Hide Close from the diode: asyncWriter closes the file once.
93100 var sink io.Writer = struct{ io.Writer }{file}
94101 if term.IsTerminal(int(os.Stderr.Fd())) {
@@ -127,11 +134,14 @@ func (a asyncWriter) Close() error {
127134 }
128135
129136 func pruneRuns(dir string) {
130- runs, _ := filepath.Glob(filepath.Join(dir, "2*.log"))
131- sort.Strings(runs)
132- for len(runs) > keepRuns {
133- _ = os.Remove(runs[0])
134- runs = runs[1:]
137+ // Watchdog stall dumps (stall-<time>-<loop>.txt) rotate like runs.
138+ for _, pattern := range []string{"2*.log", "2*.crash", "stall-*.txt"} {
139+ runs, _ := filepath.Glob(filepath.Join(dir, pattern))
140+ sort.Strings(runs)
141+ for len(runs) > keepRuns {
142+ _ = os.Remove(runs[0])
143+ runs = runs[1:]
144+ }
135145 }
136146 }
137147
@@ -7,6 +7,7 @@ import (
7 "io"7 "io"
8 "os"8 "os"
9 "path/filepath"9 "path/filepath"
10+ runtimedebug "runtime/debug"
10 "sort"11 "sort"
11 "strings"12 "strings"
12 "time"13 "time"
@@ -89,6 +90,12 @@ func Open(ctx context.Context, backend, level, debug string) (context.Context, f
89 return nil, nil, err90 return nil, nil, err
90 }91 }
91 pruneRuns(dir)92 pruneRuns(dir)
93+ // Queued entries are lost on a fatal crash: the runtime's own report
94+ // (panic and every stack) goes to its own file, besides stderr.
95+ if crash, err := os.OpenFile(filepath.Join(dir, strings.TrimSuffix(name, ".log")+".crash"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o600); err == nil {
96+ _ = runtimedebug.SetCrashOutput(crash, runtimedebug.CrashOptions{})
97+ _ = crash.Close() // SetCrashOutput keeps its own duplicate
98+ }
92 // Hide Close from the diode: asyncWriter closes the file once.99 // Hide Close from the diode: asyncWriter closes the file once.
93 var sink io.Writer = struct{ io.Writer }{file}100 var sink io.Writer = struct{ io.Writer }{file}
94 if term.IsTerminal(int(os.Stderr.Fd())) {101 if term.IsTerminal(int(os.Stderr.Fd())) {
@@ -127,11 +134,14 @@ func (a asyncWriter) Close() error {
127 }134 }
128 135
129 func pruneRuns(dir string) {136 func pruneRuns(dir string) {
130- runs, _ := filepath.Glob(filepath.Join(dir, "2*.log"))137+ // Watchdog stall dumps (stall-<time>-<loop>.txt) rotate like runs.
131- sort.Strings(runs)138+ for _, pattern := range []string{"2*.log", "2*.crash", "stall-*.txt"} {
132- for len(runs) > keepRuns {139+ runs, _ := filepath.Glob(filepath.Join(dir, pattern))
133- _ = os.Remove(runs[0])140+ sort.Strings(runs)
134- runs = runs[1:]141+ for len(runs) > keepRuns {
142+ _ = os.Remove(runs[0])
143+ runs = runs[1:]
144+ }
135 }145 }
136 }146 }
137 147

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 23

Tags 10

↑↓ moveenter openesc close