From 3f6c45a41f5a5e71f8ab13699dd1607ee559b96c Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 20 Feb 2025 17:42:00 +0100 Subject: [PATCH] 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. --- mlog/log.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mlog/log.go b/mlog/log.go index 122599a..2b5a9dc 100644 --- a/mlog/log.go +++ b/mlog/log.go @@ -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 == "" {