1
0
mirror of https://github.com/rs/zerolog synced 2026-06-08 17:13:30 +00:00

Add the ability to discard an event from a hook

The Discard method has been added to the Event type so it can be called
from a hook to prevent the event from behing printed. This new method
works outside of the context of a hook too.

Fixes #90
This commit is contained in:
Olivier Poitrey
2018-07-26 15:53:02 -07:00
parent bae001d86b
commit 71e1f5e052
3 changed files with 147 additions and 199 deletions
+9
View File
@@ -6,6 +6,15 @@ type Hook interface {
Run(e *Event, level Level, message string)
}
// HookFunc is an adaptor to allow the use of an ordinary function
// as a Hook.
type HookFunc func(e *Event, level Level, message string)
// Run implements the Hook interface.
func (h HookFunc) Run(e *Event, level Level, message string) {
h(e, level, message)
}
// LevelHook applies a different hook for each level.
type LevelHook struct {
NoLevelHook, DebugHook, InfoHook, WarnHook, ErrorHook, FatalHook, PanicHook Hook