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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user