MCPcopy
hub / github.com/rs/zerolog / TriggerLevelWriter

Struct TriggerLevelWriter

writer.go:237–253  ·  view source on GitHub ↗

TriggerLevelWriter buffers log lines at the ConditionalLevel or below until a trigger level (or higher) line is emitted. Log lines with level higher than ConditionalLevel are always written out to the destination writer. If trigger never happens, buffered log lines are never written out. It can be

Source from the content-addressed store, hash-verified

235//
236// It can be used to configure "log level per request".
237type TriggerLevelWriter struct {
238 // Destination writer. If LevelWriter is provided (usually), its WriteLevel is used
239 // instead of Write.
240 io.Writer
241
242 // ConditionalLevel is the level (and below) at which lines are buffered until
243 // a trigger level (or higher) line is emitted. Usually this is set to DebugLevel.
244 ConditionalLevel Level
245
246 // TriggerLevel is the lowest level that triggers the sending of the conditional
247 // level lines. Usually this is set to ErrorLevel.
248 TriggerLevel Level
249
250 buf *bytes.Buffer
251 triggered bool
252 mu sync.Mutex
253}
254
255func (w *TriggerLevelWriter) WriteLevel(l Level, p []byte) (n int, err error) {
256 w.mu.Lock()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected