diff options
Diffstat (limited to 'hotline/panic.go')
| -rw-r--r-- | hotline/panic.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/hotline/panic.go b/hotline/panic.go index d7376db..2207911 100644 --- a/hotline/panic.go +++ b/hotline/panic.go @@ -1,15 +1,16 @@ package hotline import ( - "fmt" "log/slog" "runtime/debug" ) -// dontPanic logs panics instead of crashing +// dontPanic recovers from a panic and logs it (with a stack trace) instead of +// letting it crash the goroutine. The trace is recorded via the structured +// logger only; it is intentionally not written to stdout, so a client that can +// repeatedly trigger a panic cannot flood stdout. func dontPanic(logger *slog.Logger) { if r := recover(); r != nil { - fmt.Println("stacktrace from panic: \n" + string(debug.Stack())) logger.Error("PANIC", "err", r, "trace", string(debug.Stack())) } } |