-
Notifications
You must be signed in to change notification settings - Fork 1
/
filter.go
38 lines (31 loc) · 822 Bytes
/
filter.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
38
package glo
// Filter checks a log line against custom logic
type Filter interface {
Check(Level, string, ...interface{}) bool
}
// NewFilterLevel checks the level of the log (inclusive)
func NewFilterLevel(min Level) Filter {
return &filterLevel{min}
}
// NewFilterLevelRange checks if the level of the log is in a range (inclusive)
func NewFilterLevelRange(min, max Level) Filter {
if min > max {
t := max
max = min
min = t
}
return &filterLevelRange{min, max}
}
type filterLevel struct {
level Level
}
func (v *filterLevel) Check(level Level, line string, params ...interface{}) bool {
return level >= v.level
}
type filterLevelRange struct {
min Level
max Level
}
func (v *filterLevelRange) Check(level Level, line string, params ...interface{}) bool {
return level >= v.min && level <= v.max
}