-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
103 lines (76 loc) · 2.13 KB
/
log.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
package log
import (
"sync"
"go.uber.org/zap"
)
type Logger interface {
Debugw(msg string, keysAndValues ...interface{})
Infow(msg string, keysAndValues ...interface{})
Warnw(msg string, keysAndValues ...interface{})
Errorw(msg string, keysAndValues ...interface{})
Panicw(msg string, keysAndValues ...interface{})
Fatalw(msg string, keysAndValues ...interface{})
Sync()
}
type zapLogger struct {
z *zap.Logger
}
var _ Logger = &zapLogger{}
var (
mu sync.Mutex
std = NewLogger(NewDefaultOptions())
)
func Init(opts *Options) {
mu.Lock()
defer mu.Unlock()
std = NewLogger(opts)
}
func NewLogger(opts *Options) *zapLogger {
if opts == nil {
opts = NewDefaultOptions()
}
z := NewChannel(opts)
l := &zapLogger{z: z}
zap.RedirectStdLog(z)
return l
}
func Sync() { std.Sync() }
func (l *zapLogger) Sync() {
_ = l.z.Sync()
}
func Debugw(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Debugw(msg, keysAndValues...)
}
func (l *zapLogger) Debugw(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Debugw(msg, keysAndValues...)
}
func Infow(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Infow(msg, keysAndValues...)
}
func (l *zapLogger) Infow(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Infow(msg, keysAndValues...)
}
func Warnw(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Warnw(msg, keysAndValues...)
}
func (l *zapLogger) Warnw(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Warnw(msg, keysAndValues...)
}
func Errorw(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Errorw(msg, keysAndValues...)
}
func (l *zapLogger) Errorw(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Errorw(msg, keysAndValues...)
}
func Panicw(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Panicw(msg, keysAndValues...)
}
func (l *zapLogger) Panicw(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Panicw(msg, keysAndValues...)
}
func Fatalw(msg string, keysAndValues ...interface{}) {
std.z.Sugar().Fatalw(msg, keysAndValues...)
}
func (l *zapLogger) Fatalw(msg string, keysAndValues ...interface{}) {
l.z.Sugar().Fatalw(msg, keysAndValues...)
}