Closed bubbajoe closed 7 months ago
Closing as a found a relatively simple way to do this without a PR.
type LoggerOptions func(zerolog.Context) zerolog.Context
func (x *X) Logger(opts ...LoggerOptions) *zerolog.Logger {
logCtx := x.logger.With()
for _, opt := range opts {
logCtx = opt(logCtx)
}
logger := logCtx.Logger()
return &logger
}
func WithComponentLogger(component string) LoggerOptions {
return func(ctx zerolog.Context) zerolog.Context {
return ctx.Str("component", component)
}
}
func WithDefaultLevel(level zerolog.Level) LoggerOptions {
return func(ctx zerolog.Context) zerolog.Context {
return ctx.Str(zerolog.LevelFieldName, zerolog.LevelFieldMarshalFunc(level))
}
}
Hello I am trying to 'interface' zerolog Logger to the go Logger, so that I can see the logs as zerolog logs.
coding example here: https://go.dev/play/p/oInY8Rqgx-a
As you can see in the example, I get
???
as the log level. Perhaps, this is a bug, but assuming it isn't; I would like to request a feature where we can overwrite level for specific loggers (using hooks).I would like to propose something like this:
This basically adds
(*Event)Level(LogLevel level) *Event
which simply should set the event level.Thanks