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
| 235 | // |
| 236 | // It can be used to configure "log level per request". |
| 237 | type 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 | |
| 255 | func (w *TriggerLevelWriter) WriteLevel(l Level, p []byte) (n int, err error) { |
| 256 | w.mu.Lock() |
nothing calls this directly
no outgoing calls
no test coverage detected