diff options
| author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
|---|---|---|
| committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
| commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
| tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/github.com/sirupsen/logrus/hooks.go | |
| parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
| download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip | |
Make Nix builds work
Diffstat (limited to 'vendor/github.com/sirupsen/logrus/hooks.go')
| -rw-r--r-- | vendor/github.com/sirupsen/logrus/hooks.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/vendor/github.com/sirupsen/logrus/hooks.go b/vendor/github.com/sirupsen/logrus/hooks.go new file mode 100644 index 0000000..3f151cd --- /dev/null +++ b/vendor/github.com/sirupsen/logrus/hooks.go | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | package logrus | ||
| 2 | |||
| 3 | // A hook to be fired when logging on the logging levels returned from | ||
| 4 | // `Levels()` on your implementation of the interface. Note that this is not | ||
| 5 | // fired in a goroutine or a channel with workers, you should handle such | ||
| 6 | // functionality yourself if your call is non-blocking and you don't wish for | ||
| 7 | // the logging calls for levels returned from `Levels()` to block. | ||
| 8 | type Hook interface { | ||
| 9 | Levels() []Level | ||
| 10 | Fire(*Entry) error | ||
| 11 | } | ||
| 12 | |||
| 13 | // Internal type for storing the hooks on a logger instance. | ||
| 14 | type LevelHooks map[Level][]Hook | ||
| 15 | |||
| 16 | // Add a hook to an instance of logger. This is called with | ||
| 17 | // `log.Hooks.Add(new(MyHook))` where `MyHook` implements the `Hook` interface. | ||
| 18 | func (hooks LevelHooks) Add(hook Hook) { | ||
| 19 | for _, level := range hook.Levels() { | ||
| 20 | hooks[level] = append(hooks[level], hook) | ||
| 21 | } | ||
| 22 | } | ||
| 23 | |||
| 24 | // Fire all the hooks for the passed level. Used by `entry.log` to fire | ||
| 25 | // appropriate hooks for a log entry. | ||
| 26 | func (hooks LevelHooks) Fire(level Level, entry *Entry) error { | ||
| 27 | for _, hook := range hooks[level] { | ||
| 28 | if err := hook.Fire(entry); err != nil { | ||
| 29 | return err | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | return nil | ||
| 34 | } | ||