for trace-level logging in console format (as opposed to logfmt), print the trace as quoted string

so we can easily see the exact bytes on the wire, instead of having \n's
expanded as newlines. much easier to read. we had this in the past, but it must
have been lost in a refactor.
This commit is contained in:
Mechiel Lukkien 2025-02-20 17:42:00 +01:00
parent 95d2002e77
commit 3f6c45a41f
No known key found for this signature in database

View File

@ -575,7 +575,11 @@ func (h *handler) write(l slog.Level, r slog.Record) error {
}
}
fmt.Fprint(eb, LevelStrings[r.Level], ": ", r.Message)
msg := r.Message
if r.Level <= LevelTrace {
msg = fmt.Sprintf("%q", msg)
}
fmt.Fprint(eb, LevelStrings[r.Level], ": ", msg)
n := 0
r.Attrs(func(a slog.Attr) bool {
if n == 0 && a.Key == "err" && h.Group == "" {