Skip to content

Instantly share code, notes, and snippets.

@mkock
Created October 2, 2021 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkock/54f4c28b3769cb08f8c072da42527f6b to your computer and use it in GitHub Desktop.
Save mkock/54f4c28b3769cb08f8c072da42527f6b to your computer and use it in GitHub Desktop.
// 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