Created
October 2, 2021 20:32
-
-
Save mkock/54f4c28b3769cb08f8c072da42527f6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In zap/zapcore/core.go | |
type Core interface { | |
LevelEnabler | |
With([]Field) Core | |
Check(Entry, *CheckedEntry) *CheckedEntry | |
Write(Entry, []Field) error | |
Sync() error | |
} | |
// In zap/zapcore/hook.go | |
type hooked struct { | |
Core // Embeds the Core interface | |
funcs []func(Entry) error | |
} | |
// RegisterHooks wraps a Core and runs a collection of user-defined callback | |
// hooks each time a message is logged. Execution of the callbacks is blocking. | |
// | |
// This offers users an easy way to register simple callbacks (e.g., metrics | |
// collection) without implementing the full Core interface. | |
func RegisterHooks(core Core, hooks ...func(Entry) error) Core { | |
funcs := append([]func(Entry) error{}, hooks...) | |
return &hooked{ | |
Core: core, | |
funcs: funcs, | |
} | |
} | |
func (h *hooked) Check(ent Entry, ce *CheckedEntry) *CheckedEntry { ... } | |
func (h *hooked) With(fields []Field) Core { ... } | |
func (h *hooked) Write(ent Entry, _ []Field) error { ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment