Skip to content

Conversation

@HugoW5
Copy link

@HugoW5 HugoW5 commented Oct 23, 2025

Description:

  • Added isTerminalLogger() to httpLogFilter to detect if the underlying logger writes to a terminal
  • Exposed IsTerminal() on the base logger to allow querying terminal output capability.

Benefits

  • Prevents ANSI color codes and non-ASCII characters from appearing in JSON logs.
  • Keeps terminal debug logs readable with colors.
  • Ensures downstream log processors can reliably parse JSON logs.

Related Issue

Fixes #2281

Additional Information:

  • Terminal output (colored debug logs):
image
  • JSON file output (plain, color-free logs):
image

Checklist:

  • I have formatted my code using goimport and golangci-lint.
  • All new code is covered by unit tests.
  • This PR does not decrease the overall code coverage.
  • I have reviewed the code comments and documentation for clarity.

Copy link
Member

@Umang01-hash Umang01-hash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @HugoW5 Thanks for the PR — this is a useful quick fix.
But we should avoid using IsTerminal() or a type-assertion in the filter; since it duplicates terminal vs JSON formatting and can leak ANSI into JSON logs.

A cleaner approach could be we can add a small typed message in remotelogger (for example httpDebugMsg) that:

  • Implements logging.PrettyPrint to render ANSI-colored output for terminals.
  • Implements json.Marshaler / MarshalJSON to return an ANSI-free string for JSON/file logs.
  • Replace the Debugf(...) branches with a single f.Logger.Debug(msg) call, passing the httpDebugMsg instance.

@HugoW5
Copy link
Author

HugoW5 commented Oct 24, 2025

@Umang01-hash
Thanks for the heads up, i can propose a better solution later this week!

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.

Improper formatting in gofr debug log for remote logger

2 participants