-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
zapcore: Support ObjectMarshaler for error types #1365
Comments
justinhwang
added a commit
to justinhwang/zap
that referenced
this issue
Feb 7, 2024
Previously, implementing `ObjectMarshaler` on an error type was ignored unless the error was logged with `zap.Any` or `zap.Object`. We should respect the `ObjectMarshaler` instead as this is more flexible than the basic `error` or `fmt.Formatter` interfaces. Resolves uber-go#1365
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When error types implement the ObjectMarshaler interface and is logged as a
zap.Error
field, it is not respected by zapcore because we currently only respect the string returned by the error andfmt.Formatter
interfaces.We should prefer the
ObjectMarshaler
interface over either of these, since it provides a more flexible approach to log the error type.Note that when the error object is logged via
zap.Any
orzap.Object
, itsObjectMarshaler
implementation will be respected.The text was updated successfully, but these errors were encountered: