You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a custom type (struct) which implements LogObjectMarshaler. I would like to add extra field when logging my object but only at the debug level. However I can't get the level associated with the event passed to MarshalZerologObject(e *zerolog.Event).
Here is an example of what I am trying to do (modified from the doc) where on debug, I also log the user's age:
typeUserstruct {
NamestringAgeintCreated time.Time
}
func (uUser) MarshalZerologObject(e*zerolog.Event) {
e.Str("name", u.Name).Time("created", u.Created)
ife.level==zerolog.DebugLevel { // Doesn't really work since level is private.e.Int("age", u.Age)
}
}
I'm open to any solution to get the level, some proposals:
Modify LogObjectMarshaler to pass the event similar to hooks:
I have a custom type (
struct
) which implementsLogObjectMarshaler
. I would like to add extra field when logging my object but only at thedebug
level. However I can't get the level associated with the event passed toMarshalZerologObject(e *zerolog.Event)
.Here is an example of what I am trying to do (modified from the doc) where on debug, I also log the user's age:
I'm open to any solution to get the level, some proposals:
Modify
LogObjectMarshaler
to pass the event similar to hooks:However, this would be a breaking change for a v2.
Similarly, to the above but in a backwards compatible way, provide a new interface:
However, this would also require new methods on the event to use this new marshaler:
Add a getter on the event to retrieve the level.
Provide a standalone function which acts as a getter (to avoid polluting the API of the event), something like:
The text was updated successfully, but these errors were encountered: