-
Notifications
You must be signed in to change notification settings - Fork 573
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
Support for custom log levels #686
Comments
This isn't the solution that you're after, but a strategy I've used is to add a It is possible to use log levels lower than There is a global (Not a maintainer, just a bystander.) |
I'm indeed using an approach similar to the one you've mentioned right now - setting a specific field. IMO it is not the optimal one. |
I'm abusing zerolog to provide an auditing capability. I don't think this is recommended; for me it's just a pragmatic first step. I'm using a level value well above This means there's a couple of tradeoffs in this approach:
Given that the level can be local to the logger, it might work for you. var (
// auditLevel is the log level at which audit logs are written.
auditLevel = zerolog.Level(20)
)
// write with the audit level
logger.WithLevel(auditLevel).Str("key", val).Msg("") // no added MSG
func zerologConfiguration() {
// configure the console writer
zerolog.FormattedLevels[auditLevel] = "AUD"
// format the audit level as "audit", falling back to the default
marshal := zerolog.LevelFieldMarshalFunc
zerolog.LevelFieldMarshalFunc = func(l zerolog.Level) string {
if l == auditLevel {
return "audit"
}
return marshal(l)
}
} |
I'm using zerolog to log both regular events, and access log events using two separately configured loggers. I would like to be able to filter these events in the resulted logs easily and thinking about something like a custom log level, e.g. ACCESS. I'm wondering if introducing an option to define custom log levels, like e.g. possible with slog is something you would consider as a valuable extension. Having a new log level named ACCESS or similar for the abovesaid purpose would be fully sufficient as well.
The text was updated successfully, but these errors were encountered: