middleware: thread useColor through Panic so NoColor logger emits plain text#1094
Closed
c-tonneslan wants to merge 1 commit into
Closed
middleware: thread useColor through Panic so NoColor logger emits plain text#1094c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
…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>
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).