Skip to content

middleware: thread useColor through Panic so NoColor logger emits plain text#1094

Closed
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/logger-panic-respects-nocolor
Closed

middleware: thread useColor through Panic so NoColor logger emits plain text#1094
c-tonneslan wants to merge 1 commit into
go-chi:masterfrom
c-tonneslan:fix/logger-panic-respects-nocolor

Conversation

@c-tonneslan

Copy link
Copy Markdown

Fixes #1042.

`defaultLogEntry.Panic` forwarded straight to `PrintPrettyStack`, which hard-coded `useColor=true`. When the surrounding terminal was a TTY, panic stack traces always came out with ANSI sequences even if the request logs above them honored `NoColor=true`. That's especially noisy on a non-color sink (Docker logs, file capture) where the rest of the request logger output is plain.

Added an internal `printPrettyStackWithColor(rvr, useColor)` helper. The exported `PrintPrettyStack` keeps its default colored behavior (the standalone `Recoverer` path doesn't have a logger to inherit a NoColor setting from). `defaultLogEntry.Panic` calls the helper with its existing `useColor` field, so panic output now matches the rest of the request log.

Added `TestRequestLoggerPanicRespectsNoColor` which flips the package-level `IsTTY` flag on for the duration of the test (otherwise `cW` would skip color emission entirely and the regression wouldn't trigger in CI).

…in text

defaultLogEntry.Panic forwarded straight to PrintPrettyStack, which
hard-coded useColor=true. When the surrounding terminal was a TTY,
panic stack traces always came out with ANSI sequences even if the
request logs above them honored NoColor=true. Confusing on a non-color
sink (Docker logs, file capture) that the rest of the logger output
respected.

Add an internal printPrettyStackWithColor helper that takes the flag,
keep the exported PrintPrettyStack pointed at the same default behavior,
and pass the logger's existing useColor field through from Panic.

Fixes go-chi#1042.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
@VojtechVitek

Copy link
Copy Markdown
Contributor

Hi, #1042 was fixed via #1050 + #1131.

Thanks for your contribution.

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.

middleware.Logger: defaultLogEntry.Panic() does not respect 'NoColor' of DefaultLogFormatter

2 participants