-
Notifications
You must be signed in to change notification settings - Fork 0
/
builtin.go
131 lines (100 loc) · 3.05 KB
/
builtin.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package logger
import (
"fmt"
"log"
)
// BuiltinLogger is an adapter for built-in logger
type BuiltinLogger struct {
logger *log.Logger
level Level
}
// NewBuiltinLogger creates new BuiltinLogger
func NewBuiltinLogger(logger *log.Logger, level Level) *BuiltinLogger {
return &BuiltinLogger{logger: logger, level: level}
}
func (l *BuiltinLogger) Debugf(format string, args ...interface{}) {
l.Logf(LevelDebug, format, args...)
}
func (l *BuiltinLogger) Infof(format string, args ...interface{}) {
l.Logf(LevelInfo, format, args...)
}
func (l *BuiltinLogger) Noticef(format string, args ...interface{}) {
l.Logf(LevelNotice, format, args...)
}
func (l *BuiltinLogger) Warningf(format string, args ...interface{}) {
l.Logf(LevelWarning, format, args...)
}
func (l *BuiltinLogger) Errorf(format string, args ...interface{}) {
l.Logf(LevelError, format, args...)
}
func (l *BuiltinLogger) Alertf(format string, args ...interface{}) {
l.Logf(LevelAlert, format, args...)
}
func (l *BuiltinLogger) Criticalf(format string, args ...interface{}) {
l.Logf(LevelCritical, format, args...)
}
func (l *BuiltinLogger) Emergencyf(format string, args ...interface{}) {
l.Logf(LevelEmergency, format, args...)
}
func (l *BuiltinLogger) Logf(level Level, format string, args ...interface{}) {
l.logMessage(level, fmt.Sprintf(format, args...))
}
func (l *BuiltinLogger) Debug(args ...interface{}) {
l.Log(LevelDebug, args...)
}
func (l *BuiltinLogger) Info(args ...interface{}) {
l.Log(LevelInfo, args...)
}
func (l *BuiltinLogger) Notice(args ...interface{}) {
l.Log(LevelNotice, args...)
}
func (l *BuiltinLogger) Warning(args ...interface{}) {
l.Log(LevelWarning, args...)
}
func (l *BuiltinLogger) Error(args ...interface{}) {
l.Log(LevelError, args...)
}
func (l *BuiltinLogger) Alert(args ...interface{}) {
l.Log(LevelAlert, args...)
}
func (l *BuiltinLogger) Critical(args ...interface{}) {
l.Log(LevelCritical, args...)
}
func (l *BuiltinLogger) Emergency(args ...interface{}) {
l.Log(LevelEmergency, args...)
}
func (l *BuiltinLogger) Log(level Level, args ...interface{}) {
l.logMessage(level, fmt.Sprint(args...))
}
func (l *BuiltinLogger) IsDebugEnabled() bool {
return l.isLevelEnabled(LevelDebug)
}
func (l *BuiltinLogger) IsInfoEnabled() bool {
return l.isLevelEnabled(LevelInfo)
}
func (l *BuiltinLogger) IsNoticeEnabled() bool {
return l.isLevelEnabled(LevelNotice)
}
func (l *BuiltinLogger) IsWarningEnabled() bool {
return l.isLevelEnabled(LevelWarning)
}
func (l *BuiltinLogger) IsErrorEnabled() bool {
return l.isLevelEnabled(LevelError)
}
func (l *BuiltinLogger) IsAlertEnabled() bool {
return l.isLevelEnabled(LevelAlert)
}
func (l *BuiltinLogger) IsCriticalEnabled() bool {
return l.isLevelEnabled(LevelCritical)
}
func (l *BuiltinLogger) IsEmergencyEnabled() bool {
return l.isLevelEnabled(LevelEmergency)
}
func (l *BuiltinLogger) isLevelEnabled(level Level) bool {
return level <= l.level
}
func (l *BuiltinLogger) logMessage(level Level, message string) {
if l.isLevelEnabled(level) {
l.logger.Print(fmt.Sprintf("[%s] %s", level, message))
}
}