-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.go
More file actions
284 lines (227 loc) · 8.79 KB
/
default.go
File metadata and controls
284 lines (227 loc) · 8.79 KB
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package logger
import (
"context"
"go.uber.org/zap"
)
var defaultLogger = NewLoggerWith(zap.NewNop(), zap.NewAtomicLevel())
// ReplaceGlobals replaces the global Log only once.
func ReplaceGlobals(logger *Log) { defaultLogger = logger }
// UnderlyingLogger underlying global logger.
func UnderlyingLogger() *Log { return defaultLogger }
// SetNewCallerCore overwrite with new caller core
func SetNewCallerCore(c *CallerCore) *Log {
return defaultLogger.SetNewCallerCore(c)
}
// AddCallerSkip add the number of callers skipped by caller annotation.
func AddCallerSkip(callerSkip int) *Log {
return defaultLogger.AddCallerSkip(callerSkip)
}
// AddCallerSkipPackage add the caller skip package.
func AddCallerSkipPackage(vs ...string) *Log {
return defaultLogger.AddCallerSkipPackage(vs...)
}
// SetCallerLevel set the caller level.
func SetCallerLevel(lv Level) *Log {
return defaultLogger.SetCallerLevel(lv)
}
// UseExternalCallerLevel use external caller level, which controller by user.
func UseExternalCallerLevel(lvl AtomicLevel) *Log {
return defaultLogger.UseExternalCallerLevel(lvl)
}
// UnderlyingCallerLevel get underlying caller level.
func UnderlyingCallerLevel() AtomicLevel {
return defaultLogger.UnderlyingCallerLevel()
}
// SetLevelWithText alters the logging level.
// ParseAtomicLevel set the logging level based on a lowercase or all-caps ASCII
// representation of the log level.
// If the provided ASCII representation is
// invalid an error is returned.
func SetLevelWithText(text string) error { return defaultLogger.SetLevelWithText(text) }
// SetLevel alters the logging level.
func SetLevel(lv Level) *Log { return defaultLogger.SetLevel(lv) }
// GetLevel returns the minimum enabled log level.
func GetLevel() Level { return defaultLogger.GetLevel() }
// Enabled returns true if the given level is at or above this level.
func Enabled(lvl Level) bool { return defaultLogger.Enabled(lvl) }
// V returns true if the given level is at or above this level.
// same as Enabled
func V(lvl Level) bool { return defaultLogger.V(lvl) }
// Sugar wraps the Logger to provide a more ergonomic, but slightly slower,
// API. Sugaring a Logger is quite inexpensive, so it's reasonable for a
// single application to use both Loggers and SugaredLoggers, converting
// between them on the boundaries of performance-sensitive code.
func Sugar() *zap.SugaredLogger { return defaultLogger.Sugar() }
// Logger return internal logger
func Logger() *zap.Logger { return defaultLogger.Logger() }
// ExtendDefaultHook set default hook, which hold always until you call [Event.Msg]/[Event.Print]/[Event.Printf].
func ExtendDefaultHook(hs ...Hook) *Log {
return defaultLogger.ExtendDefaultHook(hs...)
}
// ExtendDefaultHookFunc set default hook, which hold always until you call [Event.Msg]/[Event.Print]/[Event.Printf].
func ExtendDefaultHookFunc(hs ...HookFunc) *Log {
return defaultLogger.ExtendDefaultHookFunc(hs...)
}
// ExtendHook creates a child log with extend Hook.
func ExtendHook(hs ...Hook) *Log {
return defaultLogger.ExtendHook(hs...)
}
// ExtendHookFunc creates a child log with extend Hook.
func ExtendHookFunc(hs ...HookFunc) *Log {
return defaultLogger.ExtendHookFunc(hs...)
}
// WithNewHook creates a child log with new hook without default hook.
func WithNewHook(hs ...Hook) *Log {
return defaultLogger.WithNewHook(hs...)
}
// WithNewHookFunc creates a child log with new hook func without default hook.
func WithNewHookFunc(hs ...HookFunc) *Log {
return defaultLogger.WithNewHookFunc(hs...)
}
// With creates a child log and adds structured context to it. Fields added
// to the child don't affect the parent, and vice versa.
//
// NOTICE: if you do not need a child log, use [Event.With] instead.
func With(fields ...Field) *Log { return defaultLogger.With(fields...) }
// Named adds a sub-scope to the logger's name. See Log.Named for details.
func Named(name string) *Log { return defaultLogger.Named(name) }
// Sync flushes any buffered log entries.
func Sync() error { return defaultLogger.Sync() }
// OnLevel starts a new message with customize level.
//
// You must call Msg on the returned event in order to send the event.
func OnLevel(level Level) *Event {
return defaultLogger.OnLevel(level)
}
// OnLevelContext starts a new message with customize level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnLevelContext(ctx context.Context, level Level) *Event {
return defaultLogger.OnLevel(level).WithContext(ctx)
}
// OnDebug starts a new message with [DebugLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnDebug() *Event {
return defaultLogger.OnLevel(DebugLevel)
}
// Debug starts a new message with [DebugLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnDebugContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(DebugLevel).WithContext(ctx)
}
// OnInfo starts a new message with [InfoLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnInfo() *Event {
return defaultLogger.OnLevel(InfoLevel)
}
// OnInfoContext starts a new message with [InfoLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnInfoContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(InfoLevel).WithContext(ctx)
}
// OnWarn starts a new message with [WarnLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnWarn() *Event {
return defaultLogger.OnLevel(WarnLevel)
}
// OnWarnContext starts a new message with [WarnLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnWarnContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(WarnLevel).WithContext(ctx)
}
// OnError starts a new message with [ErrorLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnError() *Event {
return defaultLogger.OnLevel(ErrorLevel)
}
// OnErrorContext starts a new message with [ErrorLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnErrorContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(ErrorLevel).WithContext(ctx)
}
// OnDPanic starts a new message with [DPanicLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnDPanic() *Event {
return defaultLogger.OnLevel(DPanicLevel)
}
// OnDPanicContext starts a new message with [DPanicLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnDPanicContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(DPanicLevel).WithContext(ctx)
}
// OnPanic starts a new message with [PanicLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnPanic() *Event {
return defaultLogger.OnLevel(PanicLevel)
}
// OnPanicContext starts a new message with [PanicLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnPanicContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(PanicLevel).WithContext(ctx)
}
// OnFatal starts a new message with [FatalLevel] level.
//
// You must call Msg on the returned event in order to send the event.
func OnFatal() *Event {
return defaultLogger.OnLevel(FatalLevel)
}
// OnFatalContext starts a new message with [FatalLevel] level, and adds the Go Context to the *Event context.
//
// You must call Msg on the returned event in order to send the event.
func OnFatalContext(ctx context.Context) *Event {
return defaultLogger.OnLevel(FatalLevel).WithContext(ctx)
}
func Debug(args ...any) {
OnDebug().Print(args...)
}
func Info(args ...any) {
OnInfo().Print(args...)
}
func Warn(args ...any) {
OnWarn().Print(args...)
}
func Error(args ...any) {
OnError().Print(args...)
}
func Panic(args ...any) {
OnPanic().Print(args...)
}
func DPanic(args ...any) {
OnDPanic().Print(args...)
}
func Fatal(args ...any) {
OnFatal().Print(args...)
}
func Debugf(template string, args ...any) {
OnDebug().Printf(template, args...)
}
func Infof(template string, args ...any) {
OnInfo().Printf(template, args...)
}
func Warnf(template string, args ...any) {
OnWarn().Printf(template, args...)
}
func Errorf(template string, args ...any) {
OnError().Printf(template, args...)
}
func Panicf(template string, args ...any) {
OnPanic().Printf(template, args...)
}
func DPanicf(template string, args ...any) {
OnDPanic().Printf(template, args...)
}
func Fatalf(template string, args ...any) {
OnFatal().Printf(template, args...)
}