This repository has been archived by the owner on May 8, 2024. It is now read-only.
generated from things-labs/cicd-go-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefalt.go
282 lines (256 loc) · 9.23 KB
/
defalt.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
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
package log
import (
"context"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var defaultLogger = NewLoggerWith(zap.NewNop(), zap.NewAtomicLevel())
// ReplaceGlobals replaces the global Log only once.
func ReplaceGlobals(logger *Log) { defaultLogger = logger }
// 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 zapcore.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 int) bool { return defaultLogger.V(lvl) }
// SetDefaultValuer set default field function, which hold always until you call WithContext.
// suggest
func SetDefaultValuer(vs ...Valuer) *Log {
return defaultLogger.SetDefaultValuer(vs...)
}
// WithValuer with field function.
func WithValuer(vs ...Valuer) *Log {
return defaultLogger.WithValuer(vs...)
}
// WithNewValuer return log with new Valuer function without default Valuer.
func WithNewValuer(fs ...Valuer) *Log {
return defaultLogger.WithNewValuer(fs...)
}
// WithContext return log with inject context.
//
// Deprecated: Use XXXContext to inject context. such as DebugContext.
func WithContext(ctx context.Context) *Log {
return defaultLogger.WithContext(ctx)
}
// 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() }
// With adds a variadic number of fields to the logging context. It accepts a
// mix of strongly-typed Field objects and loosely-typed key-value pairs. When
// processing pairs, the first element of the pair is used as the field key
// and the second as the field value.
//
// For example,
//
// sugaredLogger.With(
// "hello", "world",
// "failure", errors.New("oh no"),
// "count", 42,
// "user", User{Name: "alice"},
// )
//
// is the equivalent of
//
// unsugared.With(
// String("hello", "world"),
// String("failure", "oh no"),
// Stack(),
// Int("count", 42),
// Object("user", User{Name: "alice"}),
// )
//
// Note that the keys in key-value pairs should be strings. In development,
// passing a non-string key panics. In production, the logger is more
// forgiving: a separate error is logged, but the key-value pair is skipped
// and execution continues. Passing an orphaned key triggers similar behavior:
// panics in development and errors in production.
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() }
// ****** named after the log level or ending in "Context" for log.Print-style logging
func Debug(args ...any) {
defaultLogger.Debug(args...)
}
func DebugContext(ctx context.Context, args ...any) {
defaultLogger.DebugContext(ctx, args...)
}
func Info(args ...any) {
defaultLogger.Info(args...)
}
func InfoContext(ctx context.Context, args ...any) {
defaultLogger.InfoContext(ctx, args...)
}
func Warn(args ...any) {
defaultLogger.Warn(args...)
}
func WarnContext(ctx context.Context, args ...any) {
defaultLogger.WarnContext(ctx, args...)
}
func Error(args ...any) {
defaultLogger.Error(args...)
}
func ErrorContext(ctx context.Context, args ...any) {
defaultLogger.ErrorContext(ctx, args...)
}
func DPanic(args ...any) {
defaultLogger.DPanic(args...)
}
func DPanicContext(ctx context.Context, args ...any) {
defaultLogger.DPanicContext(ctx, args...)
}
func Panic(args ...any) {
defaultLogger.Panic(args...)
}
func PanicContext(ctx context.Context, args ...any) {
defaultLogger.PanicContext(ctx, args...)
}
func Fatal(args ...any) {
defaultLogger.Fatal(args...)
}
func FatalContext(ctx context.Context, args ...any) {
defaultLogger.FatalContext(ctx, args...)
}
// ****** ending in "f" or "fContext" for log.Printf-style logging
func Debugf(template string, args ...any) {
defaultLogger.Debugf(template, args...)
}
func DebugfContext(ctx context.Context, template string, args ...any) {
defaultLogger.DebugfContext(ctx, template, args...)
}
func Infof(template string, args ...any) {
defaultLogger.Infof(template, args...)
}
func InfofContext(ctx context.Context, template string, args ...any) {
defaultLogger.InfofContext(ctx, template, args...)
}
func Warnf(template string, args ...any) {
defaultLogger.Warnf(template, args...)
}
func WarnfContext(ctx context.Context, template string, args ...any) {
defaultLogger.WarnfContext(ctx, template, args...)
}
func Errorf(template string, args ...any) {
defaultLogger.Errorf(template, args...)
}
func ErrorfContext(ctx context.Context, template string, args ...any) {
defaultLogger.ErrorfContext(ctx, template, args...)
}
func DPanicf(template string, args ...any) {
defaultLogger.DPanicf(template, args...)
}
func DPanicfContext(ctx context.Context, template string, args ...any) {
defaultLogger.DPanicfContext(ctx, template, args...)
}
func Panicf(template string, args ...any) {
defaultLogger.Panicf(template, args...)
}
func PanicfContext(ctx context.Context, template string, args ...any) {
defaultLogger.PanicfContext(ctx, template, args...)
}
func Fatalf(template string, args ...any) {
defaultLogger.Fatalf(template, args...)
}
func FatalfContext(ctx context.Context, template string, args ...any) {
defaultLogger.FatalfContext(ctx, template, args...)
}
// ****** ending in "w" or "wContext" for loosely-typed structured logging
func Debugw(msg string, keysAndValues ...any) {
defaultLogger.Debugw(msg, keysAndValues...)
}
func DebugwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.DebugwContext(ctx, msg, keysAndValues...)
}
func Infow(msg string, keysAndValues ...any) {
defaultLogger.Infow(msg, keysAndValues...)
}
func InfowContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.InfowContext(ctx, msg, keysAndValues...)
}
func Warnw(msg string, keysAndValues ...any) {
defaultLogger.Warnw(msg, keysAndValues...)
}
func WarnwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.WarnwContext(ctx, msg, keysAndValues...)
}
func Errorw(msg string, keysAndValues ...any) {
defaultLogger.Errorw(msg, keysAndValues...)
}
func ErrorwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.ErrorwContext(ctx, msg, keysAndValues...)
}
func DPanicw(msg string, keysAndValues ...any) {
defaultLogger.DPanicw(msg, keysAndValues...)
}
func DPanicwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.DPanicwContext(ctx, msg, keysAndValues...)
}
func Panicw(msg string, keysAndValues ...any) {
defaultLogger.Panicw(msg, keysAndValues...)
}
func PanicwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.PanicwContext(ctx, msg, keysAndValues...)
}
func Fatalw(msg string, keysAndValues ...any) {
defaultLogger.Fatalw(msg, keysAndValues...)
}
func FatalwContext(ctx context.Context, msg string, keysAndValues ...any) {
defaultLogger.FatalwContext(ctx, msg, keysAndValues...)
}
// ****** ending in "x" or "xContext" for structured logging
func Debugx(msg string, fields ...Field) {
defaultLogger.Debugx(msg, fields...)
}
func DebugxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.DebugxContext(ctx, msg, fields...)
}
func Infox(msg string, fields ...Field) {
defaultLogger.Infox(msg, fields...)
}
func InfoxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.InfoxContext(ctx, msg, fields...)
}
func Warnx(msg string, fields ...Field) {
defaultLogger.Warnx(msg, fields...)
}
func WarnxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.WarnxContext(ctx, msg, fields...)
}
func Errorx(msg string, fields ...Field) {
defaultLogger.Errorx(msg, fields...)
}
func ErrorxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.ErrorxContext(ctx, msg, fields...)
}
func DPanicx(msg string, fields ...Field) {
defaultLogger.DPanicx(msg, fields...)
}
func DPanicxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.DPanicxContext(ctx, msg, fields...)
}
func Panicx(msg string, fields ...Field) {
defaultLogger.Panicx(msg, fields...)
}
func PanicxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.PanicxContext(ctx, msg, fields...)
}
func Fatalx(msg string, fields ...Field) {
defaultLogger.Fatalx(msg, fields...)
}
func FatalxContext(ctx context.Context, msg string, fields ...Field) {
defaultLogger.FatalxContext(ctx, msg, fields...)
}