-
Notifications
You must be signed in to change notification settings - Fork 0
/
jog.go
196 lines (167 loc) · 3.09 KB
/
jog.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package jog
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type LogLevel int
const (
LevelProd LogLevel = iota
LevelDev
)
var instance Logger
func New(level ...LogLevel) Logger {
ll := LevelProd
if len(level) == 0 {
ll = LevelDev
} else {
ll = level[0]
}
j := &jLog{}
zapCfg := zap.NewProductionConfig()
if ll == LevelDev {
zapCfg = zap.NewDevelopmentConfig()
zapCfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
}
j.zapLogger, _ = zapCfg.Build()
j.zapSugar = j.zapLogger.Sugar().WithOptions(zap.AddCallerSkip(2))
instance = j
return j
}
func GetLogger() Logger {
return instance
}
func GetZapSugaredLogger() *zap.SugaredLogger {
if instance == nil {
New()
}
return instance.GetZapSugarLogger()
}
func GetZapLogger() *zap.Logger {
if instance == nil {
New()
}
return instance.GetZapLogger()
}
func Close() {
instance.Close()
}
func Debug(args ...any) {
if instance == nil {
New()
}
instance.Debug(args...)
}
func Log(args ...interface{}) {
if instance == nil {
New()
}
instance.Log(args...)
}
func Info(args ...interface{}) {
if instance == nil {
New()
}
instance.Info(args...)
}
func Warn(args ...interface{}) {
if instance == nil {
New()
}
instance.Warn(args...)
}
func Error(args ...interface{}) {
if instance == nil {
New()
}
instance.Error(args...)
}
func Fatal(args ...interface{}) {
if instance == nil {
New()
}
instance.Fatal(args...)
}
func Panic(args ...interface{}) {
if instance == nil {
New()
}
instance.Panic(args...)
}
func Debugf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Debugf(format, args...)
}
func Logf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Logf(format, args...)
}
func Infof(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Infof(format, args...)
}
func Warnf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Warnf(format, args...)
}
func Errorf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Errorf(format, args...)
}
func Fatalf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Fatalf(format, args...)
}
func Panicf(format string, args ...interface{}) {
if instance == nil {
New()
}
instance.Panicf(format, args...)
}
func Debugw(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Debugw(msg, keysAndValues...)
}
func Infow(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Infow(msg, keysAndValues...)
}
func Warnw(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Warnw(msg, keysAndValues...)
}
func Errorw(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Errorw(msg, keysAndValues...)
}
func Fatalw(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Fatalw(msg, keysAndValues...)
}
func Panicw(msg string, keysAndValues ...interface{}) {
if instance == nil {
New()
}
instance.Panicw(msg, keysAndValues...)
}