-
Notifications
You must be signed in to change notification settings - Fork 0
/
logcontext.go
124 lines (106 loc) · 3.43 KB
/
logcontext.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
package logcontext
import (
"context"
"go.uber.org/zap"
)
type LogLevel int
const (
// FatalLevel logs are typically voluminous, and are usually disabled in
// production.
DebugLevel LogLevel = iota - 1
// InfoLevel is the default logging priority.
InfoLevel
// WarnLevel logs are more important than Info, but don't need individual
// human review.
WarnLevel
// ErrorLevel logs are high-priority. If an application is running smoothly,
// it shouldn't generate any error-level logs.
ErrorLevel
// DPanicLevel logs are particularly important errors. In development the
// logger panics after writing the message.
DPanicLevel
// PanicLevel logs a message, then panics.
PanicLevel
// FatalLevel logs a message, then calls os.Exit(1).
FatalLevel
)
var defLog LogContext
func init() {
defLog = NewDefStdLog()
}
type LogContext interface {
SetContextLog(c ContextLog) LogContext
SetLogLevel(level LogLevel) LogContext
SetCallerSkip(calldepth int) LogContext
Sync()
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Debugc(ctx context.Context, v ...interface{})
Debugcf(ctx context.Context, format string, v ...interface{})
Debugw(msg string, f ...zap.Field)
Debugwc(ctx context.Context, msg string, f ...zap.Field)
Info(v ...interface{})
Infof(format string, v ...interface{})
Infoc(ctx context.Context, v ...interface{})
Infocf(ctx context.Context, format string, v ...interface{})
Infow(msg string, f ...zap.Field)
Infowc(ctx context.Context, msg string, f ...zap.Field)
Print(v ...interface{})
Println(v ...interface{})
Printf(format string, v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Warnc(ctx context.Context, v ...interface{})
Warncf(ctx context.Context, format string, v ...interface{})
Warnw(msg string, f ...zap.Field)
Warnwc(ctx context.Context, msg string, f ...zap.Field)
Error(v ...interface{})
Errorf(format string, v ...interface{})
Errorc(ctx context.Context, v ...interface{})
Errorcf(ctx context.Context, format string, v ...interface{})
Errorw(msg string, f ...zap.Field)
Errorwc(ctx context.Context, msg string, f ...zap.Field)
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Fatalc(ctx context.Context, v ...interface{})
Fatalcf(ctx context.Context, format string, v ...interface{})
Fatalw(msg string, f ...zap.Field)
Fatalwc(ctx context.Context, msg string, f ...zap.Field)
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Panicc(ctx context.Context, v ...interface{})
Paniccf(ctx context.Context, format string, v ...interface{})
Panicw(msg string, f ...zap.Field)
Panicwc(ctx context.Context, msg string, f ...zap.Field)
}
func SetLog(log LogContext) LogContext {
defLog = log
return defLog
}
func SetContextLog(c ContextLog) LogContext {
return defLog.SetContextLog(c)
}
func SetLogLevel(level LogLevel) LogContext {
return defLog.SetLogLevel(level)
}
func SetCallerSkip(calldepth int) LogContext {
return defLog.SetCallerSkip(calldepth)
}
func Debug(v ...interface{}) {
defLog.Debug(v...)
}
func Debugf(format string, v ...interface{}) {
defLog.Debugf(format, v...)
}
func Debugc(ctx context.Context, v ...interface{}) {
defLog.Debugc(ctx, v...)
}
func Debugcf(ctx context.Context, format string, v ...interface{}) {
defLog.Debugcf(ctx, format, v...)
}
func Debugw(msg string, f ...zap.Field) {
defLog.Debugw(msg, f...)
}
func Debugwc(ctx context.Context, msg string, f ...zap.Field) {
defLog.Debugwc(ctx, msg, f...)
}