-
Notifications
You must be signed in to change notification settings - Fork 0
/
zap.go
96 lines (79 loc) · 1.78 KB
/
zap.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
package common
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
var(
logger *zap.SugaredLogger
)
func init() {
//日志文件名称
fileName := "micro.log"
syncWriter:= zapcore.AddSync(
&lumberjack.Logger{
Filename: fileName, //文件名称
MaxSize: 512,//MB
//MaxAge: 0,
MaxBackups: 0, //最大备份
LocalTime: true,
Compress: true, //是否启用压缩
})
//编码
encoder:=zap.NewProductionEncoderConfig()
//时间格式
encoder.EncodeTime = zapcore.ISO8601TimeEncoder
core:= zapcore.NewCore(
// 编码器
zapcore.NewJSONEncoder(encoder),
syncWriter,
//
zap.NewAtomicLevelAt(zap.DebugLevel))
log := zap.New(
core,
zap.AddCaller(),
zap.AddCallerSkip(1))
logger = log.Sugar()
}
func Debug(args ...interface{}) {
logger.Debug(args)
}
func Debugf(template string, args ...interface{}) {
logger.Debugf(template, args...)
}
func Info(args ...interface{}) {
logger.Info(args...)
}
func Infof(template string, args ...interface{}) {
logger.Infof(template, args...)
}
func Warn(args ...interface{}) {
logger.Warn(args...)
}
func Warnf(template string, args ...interface{}) {
logger.Warnf(template, args...)
}
func Error(args ...interface{}) {
logger.Error(args...)
}
func Errorf(template string, args ...interface{}) {
logger.Errorf(template, args...)
}
func DPanic(args ...interface{}) {
logger.DPanic(args...)
}
func DPanicf(template string, args ...interface{}) {
logger.DPanicf(template, args...)
}
func Panic(args ...interface{}) {
logger.Panic(args...)
}
func Panicf(template string, args ...interface{}) {
logger.Panicf(template, args...)
}
func Fatal(args ...interface{}) {
logger.Fatal(args...)
}
func Fatalf(template string, args ...interface{}) {
logger.Fatalf(template, args...)
}