-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
93 lines (71 loc) · 2.42 KB
/
logger.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
package logger
const (
logLevelTrace = 0
logLevelDebug = 1
logLevelInfo = 2
logLevelWarn = 3
logLevelError = 4
)
type levelLogger interface {
Log(level int, msg string, fields ...any)
LogArgs(level int, args map[string]any, msg string, fields ...any)
}
type Logger interface {
Trace(msg string, fields ...any)
TraceArgs(args map[string]any, msg string, fields ...any)
Debug(msg string, fields ...any)
DebugArgs(args map[string]any, msg string, fields ...any)
Info(msg string, fields ...any)
InfoArgs(args map[string]any, msg string, fields ...any)
Warn(msg string, fields ...any)
WarnArgs(args map[string]any, msg string, fields ...any)
Error(msg string, fields ...any)
ErrorArgs(args map[string]any, msg string, fields ...any)
Err(err error, msg string, fields ...any)
ErrArgs(err error, args map[string]any, msg string, fields ...any)
}
func wrap(ll levelLogger) Logger {
return &levelWrapper{ll}
}
type levelWrapper struct {
ll levelLogger
}
func (w *levelWrapper) Trace(msg string, fields ...any) {
w.ll.Log(logLevelTrace, msg, fields...)
}
func (w *levelWrapper) TraceArgs(args map[string]any, msg string, fields ...any) {
w.ll.LogArgs(logLevelTrace, args, msg, fields...)
}
func (w *levelWrapper) Debug(msg string, fields ...any) {
w.ll.Log(logLevelDebug, msg, fields...)
}
func (w *levelWrapper) DebugArgs(args map[string]any, msg string, fields ...any) {
w.ll.LogArgs(logLevelDebug, args, msg, fields...)
}
func (w *levelWrapper) Info(msg string, fields ...any) {
w.ll.Log(logLevelInfo, msg, fields...)
}
func (w *levelWrapper) InfoArgs(args map[string]any, msg string, fields ...any) {
w.ll.LogArgs(logLevelInfo, args, msg, fields...)
}
func (w *levelWrapper) Warn(msg string, fields ...any) {
w.ll.Log(logLevelWarn, msg, fields...)
}
func (w *levelWrapper) WarnArgs(args map[string]any, msg string, fields ...any) {
w.ll.LogArgs(logLevelWarn, args, msg, fields...)
}
func (w *levelWrapper) Error(msg string, fields ...any) {
w.ll.Log(logLevelError, msg, fields...)
}
func (w *levelWrapper) ErrorArgs(args map[string]any, msg string, fields ...any) {
w.ll.LogArgs(logLevelError, args, msg, fields...)
}
func (w *levelWrapper) Err(err error, msg string, fields ...any) {
w.ll.LogArgs(logLevelError, map[string]any{
"error": err,
}, msg, fields...)
}
func (w *levelWrapper) ErrArgs(err error, args map[string]any, msg string, fields ...any) {
args["error"] = err
w.ll.LogArgs(logLevelError, args, msg, fields...)
}