-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog_prefix.go
80 lines (62 loc) · 1.85 KB
/
log_prefix.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
package log
import (
"os"
)
// NewLoggerWithPrefix returns a logger with prefix
func NewLoggerWithPrefix(prefix string) Logger {
return &prefixLoggerWrapper{
l: defaultLog,
prefix: prefix,
}
}
type prefixLoggerWrapper struct {
l *logger
prefix string
}
func (l *prefixLoggerWrapper) FatalEnabled() bool {
return l.l.FatalEnabled()
}
func (l *prefixLoggerWrapper) ErrorEnabled() bool {
return l.l.ErrorEnabled()
}
func (l *prefixLoggerWrapper) WarnEnabled() bool {
return l.l.WarnEnabled()
}
func (l *prefixLoggerWrapper) InfoEnabled() bool {
return l.l.InfoEnabled()
}
func (l *prefixLoggerWrapper) DebugEnabled() bool {
return l.l.DebugEnabled()
}
func (l *prefixLoggerWrapper) Info(v ...interface{}) {
l.l.logWithPrefix(infoLevel, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Infof(format string, v ...interface{}) {
l.l.logfWithPrefix(infoLevel, format, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Debug(v ...interface{}) {
l.l.logWithPrefix(debugLevel, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Debugf(format string, v ...interface{}) {
l.l.logfWithPrefix(debugLevel, format, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Warning(v ...interface{}) {
l.l.logWithPrefix(warnLevel, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Warningf(format string, v ...interface{}) {
l.l.logfWithPrefix(warnLevel, format, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Error(v ...interface{}) {
l.l.logWithPrefix(errorLevel, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Errorf(format string, v ...interface{}) {
l.l.logfWithPrefix(errorLevel, format, l.prefix, v...)
}
func (l *prefixLoggerWrapper) Fatal(v ...interface{}) {
l.l.logWithPrefix(fatalLevel, l.prefix, v...)
os.Exit(-1)
}
func (l *prefixLoggerWrapper) Fatalf(format string, v ...interface{}) {
l.l.logfWithPrefix(fatalLevel, format, l.prefix, v...)
os.Exit(-1)
}