-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
233 lines (185 loc) · 5.6 KB
/
default.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
package hlog
import (
"context"
"fmt"
"io"
"log"
"os"
)
// Fatal calls the default logger's Fatal method and then os.Exit(1).
func Fatal(v ...interface{}) {
logger.Fatal(v...)
}
// Error calls the default logger's Error method.
func Error(v ...interface{}) {
logger.Error(v...)
}
// Warn calls the default logger's Warn method.
func Warn(v ...interface{}) {
logger.Warn(v...)
}
// Notice calls the default logger's Notice method.
func Notice(v ...interface{}) {
logger.Notice(v...)
}
// Info calls the default logger's Info method.
func Info(v ...interface{}) {
logger.Info(v...)
}
// Debug calls the default logger's Debug method.
func Debug(v ...interface{}) {
logger.Debug(v...)
}
// Trace calls the default logger's Trace method.
func Trace(v ...interface{}) {
logger.Trace(v...)
}
// Fatalf calls the default logger's Fatalf method and then os.Exit(1).
func Fatalf(format string, v ...interface{}) {
logger.Fatalf(format, v...)
}
// Errorf calls the default logger's Errorf method.
func Errorf(format string, v ...interface{}) {
logger.Errorf(format, v...)
}
// Warnf calls the default logger's Warnf method.
func Warnf(format string, v ...interface{}) {
logger.Warnf(format, v...)
}
// Noticef calls the default logger's Noticef method.
func Noticef(format string, v ...interface{}) {
logger.Noticef(format, v...)
}
// Infof calls the default logger's Infof method.
func Infof(format string, v ...interface{}) {
logger.Infof(format, v...)
}
// Debugf calls the default logger's Debugf method.
func Debugf(format string, v ...interface{}) {
logger.Debugf(format, v...)
}
// Tracef calls the default logger's Tracef method.
func Tracef(format string, v ...interface{}) {
logger.Tracef(format, v...)
}
// CtxFatal calls the default logger's CtxFatal method and then os.Exit(1).
func CtxFatal(ctx context.Context, format string, v ...interface{}) {
logger.CtxFatalf(ctx, format, v...)
}
// CtxError calls the default logger's CtxError method.
func CtxError(ctx context.Context, format string, v ...interface{}) {
logger.CtxErrorf(ctx, format, v...)
}
// CtxWarn calls the default logger's CtxWarn method.
func CtxWarn(ctx context.Context, format string, v ...interface{}) {
logger.CtxWarnf(ctx, format, v...)
}
// CtxNotice calls the default logger's CtxNotice method.
func CtxNotice(ctx context.Context, format string, v ...interface{}) {
logger.CtxNoticef(ctx, format, v...)
}
// CtxInfo calls the default logger's CtxInfo method.
func CtxInfo(ctx context.Context, format string, v ...interface{}) {
logger.CtxInfof(ctx, format, v...)
}
// CtxDebug calls the default logger's CtxDebug method.
func CtxDebug(ctx context.Context, format string, v ...interface{}) {
logger.CtxDebugf(ctx, format, v...)
}
// CtxTrace calls the default logger's CtxTrace method.
func CtxTrace(ctx context.Context, format string, v ...interface{}) {
logger.CtxTracef(ctx, format, v...)
}
type defaultLogger struct {
stdlog *log.Logger
level Level
depth int
}
func (ll *defaultLogger) SetOutput(w io.Writer) {
ll.stdlog.SetOutput(w)
}
func (ll *defaultLogger) SetLevel(lv Level) {
ll.level = lv
}
func (ll *defaultLogger) logf(lv Level, format *string, v ...interface{}) {
if ll.level > lv {
return
}
msg := lv.toString()
if format != nil {
if len(v) > 0 {
msg += fmt.Sprintf(*format, v...)
} else {
msg += *format
}
} else {
msg += fmt.Sprint(v...)
}
ll.stdlog.Output(ll.depth, msg)
if lv == LevelFatal {
os.Exit(1)
}
}
func (ll *defaultLogger) Fatal(v ...interface{}) {
ll.logf(LevelFatal, nil, v...)
}
func (ll *defaultLogger) Error(v ...interface{}) {
ll.logf(LevelError, nil, v...)
}
func (ll *defaultLogger) Warn(v ...interface{}) {
ll.logf(LevelWarn, nil, v...)
}
func (ll *defaultLogger) Notice(v ...interface{}) {
ll.logf(LevelNotice, nil, v...)
}
func (ll *defaultLogger) Info(v ...interface{}) {
ll.logf(LevelInfo, nil, v...)
}
func (ll *defaultLogger) Debug(v ...interface{}) {
ll.logf(LevelDebug, nil, v...)
}
func (ll *defaultLogger) Trace(v ...interface{}) {
ll.logf(LevelTrace, nil, v...)
}
func (ll *defaultLogger) Fatalf(format string, v ...interface{}) {
ll.logf(LevelFatal, &format, v...)
}
func (ll *defaultLogger) Errorf(format string, v ...interface{}) {
ll.logf(LevelError, &format, v...)
}
func (ll *defaultLogger) Warnf(format string, v ...interface{}) {
ll.logf(LevelWarn, &format, v...)
}
func (ll *defaultLogger) Noticef(format string, v ...interface{}) {
ll.logf(LevelNotice, &format, v...)
}
func (ll *defaultLogger) Infof(format string, v ...interface{}) {
ll.logf(LevelInfo, &format, v...)
}
func (ll *defaultLogger) Debugf(format string, v ...interface{}) {
ll.logf(LevelDebug, &format, v...)
}
func (ll *defaultLogger) Tracef(format string, v ...interface{}) {
ll.logf(LevelTrace, &format, v...)
}
func (ll *defaultLogger) CtxFatalf(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelFatal, &format, v...)
}
func (ll *defaultLogger) CtxErrorf(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelError, &format, v...)
}
func (ll *defaultLogger) CtxWarnf(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelWarn, &format, v...)
}
func (ll *defaultLogger) CtxNoticef(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelNotice, &format, v...)
}
func (ll *defaultLogger) CtxInfof(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelInfo, &format, v...)
}
func (ll *defaultLogger) CtxDebugf(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelDebug, &format, v...)
}
func (ll *defaultLogger) CtxTracef(ctx context.Context, format string, v ...interface{}) {
ll.logf(LevelTrace, &format, v...)
}