-
Notifications
You must be signed in to change notification settings - Fork 0
/
hooks.go
37 lines (30 loc) · 936 Bytes
/
hooks.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package logz
import (
"io"
"github.com/rs/zerolog"
)
type LogHook struct {
Level string
}
func (h LogHook) Run(e *zerolog.Event, _ zerolog.Level, msg string) {
e.Str("level", h.Level)
}
// Hooks pass level informations to loggers.
var Hooks = zerolog.LevelHook{
DebugHook: LogHook{Level: zerolog.LevelDebugValue},
InfoHook: LogHook{Level: zerolog.LevelInfoValue},
WarnHook: LogHook{Level: zerolog.LevelWarnValue},
ErrorHook: LogHook{Level: zerolog.LevelErrorValue},
FatalHook: LogHook{Level: zerolog.LevelFatalValue},
PanicHook: LogHook{Level: zerolog.LevelPanicValue},
TraceHook: LogHook{Level: zerolog.LevelTraceValue},
NoLevelHook: LogHook{Level: ""},
}
// LevelWriter function eliminate logger based on level with manually.
// This is usable for writer loggers.
func LevelWriter(e zerolog.Logger, lvl zerolog.Level) io.Writer {
if lvl < zerolog.GlobalLevel() {
return io.Discard
}
return e
}