Skip to content

Commit

Permalink
Refactor: change Hook(h Hook) to Hook(hooks ...Hook) (#629)
Browse files Browse the repository at this point in the history
  • Loading branch information
Halimao committed Dec 24, 2023
1 parent 7fa45a4 commit 3e8ae07
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,13 @@ func (l Logger) Sample(s Sampler) Logger {
}

// Hook returns a logger with the h Hook.
func (l Logger) Hook(h Hook) Logger {
newHooks := make([]Hook, len(l.hooks), len(l.hooks)+1)
func (l Logger) Hook(hooks ...Hook) Logger {
if len(hooks) == 0 {
return l
}
newHooks := make([]Hook, len(l.hooks), len(l.hooks)+len(hooks))
copy(newHooks, l.hooks)
l.hooks = append(newHooks, h)
l.hooks = append(newHooks, hooks...)
return l
}

Expand Down
2 changes: 1 addition & 1 deletion log_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func ExampleLogger_Hook() {
var levelNameHook LevelNameHook
var messageHook MessageHook = "The message"

log := zerolog.New(os.Stdout).Hook(levelNameHook).Hook(messageHook)
log := zerolog.New(os.Stdout).Hook(levelNameHook, messageHook)

log.Info().Msg("hello world")

Expand Down

0 comments on commit 3e8ae07

Please sign in to comment.