Skip to content

Commit

Permalink
Optimize the execution efficiency of log hooks.
Browse files Browse the repository at this point in the history
  • Loading branch information
edoger committed May 13, 2021
1 parent 0e77f18 commit 0adb6c6
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions hook.go
Expand Up @@ -93,11 +93,13 @@ func (o *hookBag) Levels() []Level {

// Fire receives the summary of the log and performs the full logic of the log hook.
func (o *hookBag) Fire(s Summary) error {
if len(o.hooks) > 0 && len(o.hooks[s.Level()]) > 0 {
for _, hook := range o.hooks[s.Level()] {
if err := hook.Fire(s); err != nil {
return err
}
if len(o.hooks) == 0 || len(o.hooks[s.Level()]) == 0 {
return nil
}
hs := o.hooks[s.Level()]
for i, j := 0, len(hs); i < j; i++ {
if err := hs[i].Fire(s); err != nil {
return err
}
}
return nil
Expand Down

0 comments on commit 0adb6c6

Please sign in to comment.