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

SugaredLogger: Turn error into zap.Error #1184

Closed
abhinav opened this issue Sep 30, 2022 · 2 comments · Fixed by #1185
Closed

SugaredLogger: Turn error into zap.Error #1184

abhinav opened this issue Sep 30, 2022 · 2 comments · Fixed by #1185

Comments

@abhinav
Copy link
Collaborator

abhinav commented Sep 30, 2022

Is your feature request related to a problem? Please describe.

With Zap's sugared logger, if you provide a plain error object to Infow/Errorw/etc.,
it does not desugar the error into a zap.Field.

log.Warnw("something happened", err) // bad

log.Warnw("something happened", "err", err) // good
// desugars to
log.Desugar().Warn("something happened", zap.NamedError("err", err))

This is inconvenient for the majority case where there will be only one error.

Describe the solution you'd like

We should turn the first case into,

log.Desugar().Warn("something happened", zap.Error(err))

We could even be smart about it in desugarFields
and make sure there's only one instance of "err".
Others have to have a field name.

Describe alternatives you've considered

Add "err" next to every err argument.

Is this a breaking change?
No

@craigpastro
Copy link
Contributor

I would like to try giving this a shot if that's okay?

@abhinav
Copy link
Collaborator Author

abhinav commented Oct 5, 2022

Sure, @craigpastro!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants