logrus/hooks.go

25 lines
423 B
Go
Raw Normal View History

2014-03-11 03:22:08 +04:00
package logrus
type Hook interface {
2014-03-11 03:52:39 +04:00
Levels() []Level
2014-03-11 03:22:08 +04:00
Fire(*Entry) error
}
2014-03-11 03:52:39 +04:00
type levelHooks map[Level][]Hook
2014-03-11 03:22:08 +04:00
func (hooks levelHooks) Add(hook Hook) {
for _, level := range hook.Levels() {
hooks[level] = append(hooks[level], hook)
}
}
2014-03-11 03:52:39 +04:00
func (hooks levelHooks) Fire(level Level, entry *Entry) error {
2014-03-11 03:22:08 +04:00
for _, hook := range hooks[level] {
if err := hook.Fire(entry); err != nil {
return err
}
}
return nil
}