-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LoggerColorBehavior #40221
Add LoggerColorBehavior #40221
Conversation
Tagging subscribers to this area: @maryamariyan |
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
0cf1e17
to
37d37ac
Compare
src/libraries/Microsoft.Extensions.Logging.Console/src/ConsoleLoggerProvider.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatterOptions.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/LoggerColorBehavior.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/LoggerColorBehavior.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a few minor clean ups and I think this is ready to merge.
src/libraries/Microsoft.Extensions.Logging.Console/src/LoggerColorBehavior.cs
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put a little suggestions, other than that LGTM.
Note on LoggerColorBehavior usage:The intention behind LoggerColorBehavior is to provide formatters with a way to configure when ANSI color encoding is allowed to get padded around logged messages. Therefore, if the log message itself contains some ANSI color codes, that gets logged as-is and LoggerColorBehavior is NOT designed/meant to remove that. Sample usage:The gist sample here implements a custom formatter that does color formatting conditioned by LoggerColorBehavior. Compare that against the built-in implementation of SimpleConsoleFormatter, which skips color coding for log level here: runtime/src/libraries/Microsoft.Extensions.Logging.Console/src/SimpleConsoleFormatter.cs Lines 150 to 155 in 0f4ec15
Hence, color coding logic within either formatters may be disabled using LoggerColorBehavior, but a call like: logger.LogInformation("Random log \x1B[42mwith green background\x1B[49m message"); using either loggers will not strip out the padded color codes "\x1B[42m" and "\x1B[49m" within the message itself. |
Fixes: #37421
cc: @eerhardt @davidfowl @tarekgh