Skip to content

middleware: honour NoColor in defaultLogEntry.Panic#1086

Closed
alliasgher wants to merge 2 commits into
go-chi:masterfrom
alliasgher:fix-logger-panic-nocolor
Closed

middleware: honour NoColor in defaultLogEntry.Panic#1086
alliasgher wants to merge 2 commits into
go-chi:masterfrom
alliasgher:fix-logger-panic-nocolor

Conversation

@alliasgher

Copy link
Copy Markdown
Contributor

Summary

defaultLogEntry.Panic called PrintPrettyStack unconditionally. That function hardcodes useColor := true, so the panic stack trace was always printed with ANSI colour codes even when DefaultLogFormatter.NoColor was set to true.

Fix

  • Add PrintPrettyStackColor(rvr interface{}, useColor bool) that accepts an explicit colour flag.
  • Refactor PrintPrettyStack to delegate to it with useColor=true — no change for existing callers.
  • Refactor prettyStack.parse to receive useColor rather than hardcode it.
  • defaultLogEntry.Panic now passes l.useColor, which is derived from DefaultLogFormatter.NoColor.

Fixes #1042

@VojtechVitek

Copy link
Copy Markdown
Contributor

Needs a rebase.

defaultLogEntry.Panic called PrintPrettyStack unconditionally, which
always used ANSI colour codes regardless of the DefaultLogFormatter's
NoColor field.

Add PrintPrettyStackColor(rvr, useColor bool) and thread the flag
through prettyStack.parse. PrintPrettyStack now delegates to it with
useColor=true so existing callers are unaffected. defaultLogEntry.Panic
passes l.useColor so the panic output respects the same flag that
controls the rest of the request log.

Fixes go-chi#1042

Signed-off-by: alliasgher <alliasgher123@gmail.com>
@alliasgher alliasgher force-pushed the fix-logger-panic-nocolor branch from 22730e6 to 01faae4 Compare June 14, 2026 11:20
@alliasgher

Copy link
Copy Markdown
Contributor Author

Rebased onto master (01faae4). The wrap_writer fix that was in this branch already landed upstream, so this is now just the NoColor panic change.

Comment thread middleware/recoverer.go Outdated
Address review: only defaultLogEntry.Panic needs the useColor variant
and it lives in the same package, so PrintPrettyStackColor does not need
to be exported. Rename it to printPrettyStack; the public PrintPrettyStack
API is unchanged.

Signed-off-by: alliasgher <alliasgher123@gmail.com>
@VojtechVitek

Copy link
Copy Markdown
Contributor

Merged via #1131. Thank you!

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