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'm trying to add span contexts via apmzerolog and to do that I'd have to add a hook. The weird thing I'm encountering is that if I started a span or some other context to be appended in my logs, I'd have to call the Hook method to append the context to the logger for every log event.
The main question is zerolog suppose to only add hooks on initialization of a Logger?
I created a wrapper over a zerolog.Logger and a method called TraceContext so that I can do something like:
However, I have to attach a hook which creates a new value-based zerolog.Logger and then switch the semantics to return a pointer to a zerolog.Logger in order to chain it correctly with the other Events since the receiver for methods like Info() requires a *zerolog.Logger.
Example code:
// Logger wraps a zerolog.Logger as an adapter.typeLoggerstruct {
underlying zerolog.Logger
}
funcNewLogger(logger zerolog.Logger) *Logger {
return&Logger{
underlying: logger,
}
}
// TraceContext attaches a context.Context to the underlying zerolog.Logger and attaches an apm trace hook.func (l*Logger) TraceContext(ctx context.Context) *zerolog.Logger {
// TODO The switching of pointer and value semantic might go against what zerolog was trying to convey,// but we need figure out if hooks are meant to be only initialized once vs being added dynamicallylogger:=l.underlying.Hook(apmzerolog.TraceContextHook(ctx))
return&logger
}
The text was updated successfully, but these errors were encountered:
I'm trying to add span contexts via apmzerolog and to do that I'd have to add a hook. The weird thing I'm encountering is that if I started a span or some other context to be appended in my logs, I'd have to call the
Hook
method to append the context to the logger for every log event.The main question is zerolog suppose to only add hooks on initialization of a
Logger
?I created a wrapper over a
zerolog.Logger
and a method calledTraceContext
so that I can do something like:However, I have to attach a hook which creates a new value-based
zerolog.Logger
and then switch the semantics to return a pointer to azerolog.Logger
in order to chain it correctly with the otherEvents
since the receiver for methods likeInfo()
requires a*zerolog.Logger
.Example code:
The text was updated successfully, but these errors were encountered: