Skip to content
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

logging: Better console encoder defaults #5109

Merged
merged 1 commit into from Oct 5, 2022
Merged

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Oct 2, 2022

This is something that has bothered me for a while, so I figured I'd do something about it now since I'm playing in the logging code lately.

The console encoder doesn't actually match the defaults that zap's default logger uses. This makes it match better with the rest of the logs when using the console encoder alongside somekind of filter, which requires you to configure an encoder to wrap.

Before:
image

After:
image

As you can see, this colorizes + uppercases the level, and makes the timestamp not useless.

Worth saying, that technically zap's default logger sniffs the TTY to figure out whether it's interactive or not, and uses JSON if non-interactive, and a "modified" console encoder if interactive. I think it might turn off color if the terminal doesn't support it. But I don't think that's worth trying to do here for these defaults, because it only affects the log level and most people get the gist even if their terminal doesn't render the color shell escapes.

This is something that has bothered me for a while, so I figured I'd do something about it now since I'm playing in the logging code lately.

The `console` encoder doesn't actually match the defaults that zap's default logger uses. This makes it match better with the rest of the logs when using the `console` encoder alongside somekind of filter, which requires you to configure an encoder to wrap.
@francislavoie francislavoie added the bug 🐞 Something isn't working label Oct 2, 2022
@francislavoie francislavoie added this to the v2.6.2 milestone Oct 2, 2022
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks, I can appreciate this :)

@mholt mholt merged commit 01e192e into master Oct 5, 2022
@mholt mholt deleted the console-encoder-defaults branch October 5, 2022 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants