-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzaplog.go
130 lines (117 loc) · 2.57 KB
/
zaplog.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
package zlog
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var (
// String ...
String = zap.String
// Any ...
Any = zap.Any
// Int64 ...
Int64 = zap.Int64
// Int ...
Int = zap.Int
// Int32 ...
Int32 = zap.Int32
// Uint ...
Uint = zap.Uint
// Duration ...
Duration = zap.Duration
// Durationp ...
Durationp = zap.Durationp
// Object ...
Object = zap.Object
// Namespace ...
Namespace = zap.Namespace
// Reflect ...
Reflect = zap.Reflect
// Skip ...
Skip = zap.Skip()
// ByteString ...
ByteString = zap.ByteString
ParseLevel = zapcore.ParseLevel
)
const (
EsModuleKey = "es"
KafkaModuleKey = "kafka"
RedisModuleKey = "redis"
)
const (
ConsoleMode = "console"
FileMode = "file"
)
var (
DevConfig = &Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
AddCaller: true,
CallerShip: 1,
Mode: ConsoleMode,
Color: true,
}
ProdConfig = &Config{
Level: zap.NewAtomicLevelAt(zap.InfoLevel),
AddCaller: true,
CallerShip: 1,
Mode: ConsoleMode,
Stacktrace: true,
Json: true,
Color: false,
}
)
var (
DefaultLogger = DevConfig.Build()
DefaultSugarLog = DefaultLogger.Sugar()
)
func UpdateLoggerLevel(level zapcore.Level) {
DevConfig.UpdateLevel(level)
ProdConfig.UpdateLevel(level)
}
func InitDefaultLogger(loggerConfig *Config) {
DefaultLogger = loggerConfig.Build()
DefaultSugarLog = DefaultLogger.Sugar()
RedisLogger.Update()
InfoEsOlivereLogger.Update()
ErrorEsOlivereLogger.Update()
KafkaSaramaLogger.Update()
GinOutPut.Update()
}
func Debugf(msg string, fields ...interface{}) {
DefaultSugarLog.Debugf(msg, fields...)
}
func Panicf(msg string, fields ...interface{}) {
DefaultSugarLog.Panicf(msg, fields...)
}
func Infof(msg string, fields ...interface{}) {
DefaultSugarLog.Infof(msg, fields...)
}
func Errorf(msg string, fields ...interface{}) {
DefaultSugarLog.Errorf(msg, fields...)
}
func Warnf(msg string, fields ...interface{}) {
DefaultSugarLog.Warnf(msg, fields...)
}
func GetZapLogger() *zap.Logger {
return DefaultLogger
}
func Info(msg string, fields ...zap.Field) {
DefaultLogger.Info(msg, fields...)
}
func Debug(msg string, fields ...zap.Field) {
DefaultLogger.Debug(msg, fields...)
}
func Warn(msg string, fields ...zap.Field) {
DefaultLogger.Warn(msg, fields...)
}
func Error(msg string, fields ...zap.Field) {
DefaultLogger.Error(msg, fields...)
}
func Panic(msg string, fields ...zap.Field) {
DefaultLogger.Panic(msg, fields...)
}
func DPanic(msg string, fields ...zap.Field) {
DefaultLogger.DPanic(msg, fields...)
}
func Sync() error {
return DefaultLogger.Sync()
}