-
Notifications
You must be signed in to change notification settings - Fork 3
/
mutable_level.go
39 lines (32 loc) · 1006 Bytes
/
mutable_level.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
package logf
import "sync/atomic"
// NewMutableLevel creates an instance of MutableLevel with the given
// starting level.
func NewMutableLevel(l Level) *MutableLevel {
return &MutableLevel{level: uint32(l)}
}
// MutableLevel allows to switch the logging level atomically.
//
// The logger does not allow to change logging level in runtime by itself.
type MutableLevel struct {
level uint32
}
// Checker is common way to get LevelChecker. Use it with every custom
// implementation of Level.
func (l *MutableLevel) Checker() LevelChecker {
return func(o Level) bool {
return l.Level().Enabled(o)
}
}
// LevelChecker implements LevelCheckerGetter.
func (l *MutableLevel) LevelChecker() LevelChecker {
return l.Checker()
}
// Level returns the current logging level.
func (l *MutableLevel) Level() Level {
return (Level)(atomic.LoadUint32(&l.level))
}
// Set switches the current logging level to the given one.
func (l *MutableLevel) Set(o Level) {
atomic.StoreUint32(&l.level, uint32(o))
}