Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v15] Prevent quoting debug reports #50823

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions lib/utils/log/handle_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,13 @@ func (s *handleState) appendAttr(a slog.Attr) bool {
}

// Handle special cases before formatting.
var traceError bool
if a.Value.Kind() == slog.KindAny {
switch v := a.Value.Any().(type) {
case *slog.Source:
a.Value = slog.StringValue(fmt.Sprintf(" %s:%d", v.File, v.Line))
case trace.Error:
traceError = true
a.Value = slog.StringValue("[" + v.DebugReport() + "]")
case error:
a.Value = slog.StringValue(fmt.Sprintf("[%v]", v))
Expand Down Expand Up @@ -161,18 +163,11 @@ func (s *handleState) appendAttr(a slog.Attr) bool {
return true
}

if a.Value.Kind() == slog.KindString && a.Key != slog.LevelKey {
val := a.Value.String()
if needsQuoting(val) {
a.Value = slog.StringValue(strconv.Quote(val))
}
}

s.appendKey(a.Key)

// Write the log key directly to avoid quoting
// color formatting that exists.
if a.Key == slog.LevelKey {
// Write the level key to avoid quoting color formatting that exists or
// [trace.Error]s so that the debug report is output in it's entirety.
if traceError || a.Key == slog.LevelKey {
s.buf.WriteString(a.Value.String())
} else {
s.appendValue(a.Value)
Expand Down
Loading