-
Notifications
You must be signed in to change notification settings - Fork 22
/
scoped.go
72 lines (64 loc) · 1.87 KB
/
scoped.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package logging
import (
"sync/atomic"
)
// LogLevel represents the level at which the logger will emit log messages
type LogLevel int32
// Set updates the LogLevel to the supplied value
func (ll *LogLevel) Set(newLevel LogLevel) {
atomic.StoreInt32((*int32)(ll), int32(newLevel))
}
// Get retrieves the current LogLevel value
func (ll *LogLevel) Get() LogLevel {
return LogLevel(atomic.LoadInt32((*int32)(ll)))
}
func (ll LogLevel) String() string {
switch ll {
case LogLevelDisabled:
return "Disabled"
case LogLevelError:
return "Error"
case LogLevelWarn:
return "Warn"
case LogLevelInfo:
return "Info"
case LogLevelDebug:
return "Debug"
case LogLevelTrace:
return "Trace"
default:
return "UNKNOWN"
}
}
const (
// LogLevelDisabled completely disables logging of any events
LogLevelDisabled LogLevel = iota
// LogLevelError is for fatal errors which should be handled by user code,
// but are logged to ensure that they are seen
LogLevelError
// LogLevelWarn is for logging abnormal, but non-fatal library operation
LogLevelWarn
// LogLevelInfo is for logging normal library operation (e.g. state transitions, etc.)
LogLevelInfo
// LogLevelDebug is for logging low-level library information (e.g. internal operations)
LogLevelDebug
// LogLevelTrace is for logging very low-level library information (e.g. network traces)
LogLevelTrace
)
// LeveledLogger is the basic pion Logger interface
type LeveledLogger interface {
Trace(msg string)
Tracef(format string, args ...interface{})
Debug(msg string)
Debugf(format string, args ...interface{})
Info(msg string)
Infof(format string, args ...interface{})
Warn(msg string)
Warnf(format string, args ...interface{})
Error(msg string)
Errorf(format string, args ...interface{})
}
// LoggerFactory is the basic pion LoggerFactory interface
type LoggerFactory interface {
NewLogger(scope string) LeveledLogger
}