forked from jensneuse/abstractlogger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel.go
More file actions
34 lines (29 loc) · 1 KB
/
Copy pathlevel.go
File metadata and controls
34 lines (29 loc) · 1 KB
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
package abstractlogger
// LevelCheck is a simple helper function to check the logging level before invoking the logging backend
// This is a very helpful optimization because it can avoid calling into variadic functions of the logging backend of your choice.
// In case of logrus this makes for a 300x improvement in performance (time/op) on a missed log level.
// In case of zap this improves the performance (time/op) by at least 69x on a missed log level.
type LevelCheck struct {
level Level
}
func NewLevelCheck(level Level) LevelCheck {
return LevelCheck{
level: level,
}
}
// Level are all possible logging levels in increasing order, starting with DebugLevel
type Level int
const (
TraceLevel Level = iota - 1
DebugLevel
InfoLevel
WarnLevel
ErrorLevel
PanicLevel
FatalLevel
)
// Check returns true if the supplied logging level should be logged.
// Because the logging levels are increasing this is a simple greater equals check.
func (l LevelCheck) Check(level Level) bool {
return level >= l.level
}