-
Notifications
You must be signed in to change notification settings - Fork 3
/
control.go
40 lines (35 loc) · 900 Bytes
/
control.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
39
40
package alog
// control determines if it should be printed as a log or not.
// Target speed: single 170, multi 79, noLog 5
type control struct {
bucket *TagBucket // this is 1032 bytes, better to be used as a pointer
Fn ControlFn
Level Level
Tags Tag
}
func newControl() control {
return control{
bucket: &TagBucket{},
Fn: nil,
Level: InfoLevel,
Tags: 0,
}
}
// Bucket will return the pointer of TagBucket in control.
func (c control) Bucket() *TagBucket {
return c.bucket
}
// Check will check if level and tag given is good to be printed.
func (c control) Check(lvl Level, tag Tag) bool {
if c.Level <= lvl || c.Tags&tag != 0 {
return true
}
return false
}
// CheckFn will check if level and tag given is good to be printed.
func (c control) CheckFn(lvl Level, tag Tag) (bool, bool) {
if c.Fn != nil {
return true, c.Fn(lvl, tag)
}
return false, false
}