zerolog
zerolog copied to clipboard
Ability to remove certain events from the sampler.
i would like to add a sampler but there are certain logs that i want them not to be sampled. for example i have an http server, and if there is a panic on certain requests, i don't want to crash the server, but i catch the request and log it. i want to always catch those regardless of the sample rates.
i can implement something like this:
type LogWriter struct {
io.Writer
sampler zerolog.Sampler
notSampled *regexp.Regexp
}
func (w *LogWriter) Write(p []byte) (n int, err error) {
if w.notSampled != nil && w.notSampled.Match(p) {
return w.Writer.Write(p)
}
if w.sampler.Sample(zerolog.NoLevel) {
return w.Writer.Write(p)
}
return 0, nil
}
but not sure this is the best way, maybe just use the noLevel for my critical events and then do a sampler for all other levels?