Skip to content

fix(log): encode control characters as valid JSON - #70

Open
Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/json-log-controls-20261121
Open

Twiink wants to merge 1 commit into
labstack:masterfrom
Twiink:fix/json-log-controls-20261121

Conversation

@Twiink

@Twiink Twiink commented Nov 21, 2026

Copy link
Copy Markdown

When an application logs output containing ANSI colors or other control characters with Info, the default JSON logger produces an invalid JSON document. For example, an escape character is encoded as Go's \x1b, which JSON decoders reject. Bell, vertical tab and NUL have the same problem.

Encode the message with encoding/json instead of Go string-literal quoting. This preserves the original message after JSON decoding and leaves the structured Infoj path unchanged.

Validation:

  • The regression test fails on four control-character messages before the change; newline/tab, quotes and the structured JSON path pass as controls.
  • go test -race -count=1 ./...
  • go vet ./...
  • gofmt and git diff --check

I checked the historical quoting change in #9 and the open logging-level change in #24; neither handles JSON control-character escaping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant