-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.go
41 lines (35 loc) · 948 Bytes
/
default.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
package log
import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"gopkg.in/natefinch/lumberjack.v2"
)
// 默认的一些配置
func DefaultEncoderConfig() zapcore.EncoderConfig {
var encoderConfig = zap.NewProductionEncoderConfig()
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
return encoderConfig
}
// 统一用json
func DefaultEncoder() zapcore.Encoder {
return zapcore.NewJSONEncoder(DefaultEncoderConfig())
}
func DefaultOption() []zap.Option {
var stackTraceLevel zap.LevelEnablerFunc = func(level zapcore.Level) bool {
return level >= zapcore.DPanicLevel
}
return []zap.Option{
zap.AddCaller(),
zap.AddStacktrace(stackTraceLevel),
}
}
// 1.不会自动清理backup
// 2.每200mb压缩一次,不按时间rotate
func DefaultLumberjackLogger() *lumberjack.Logger {
return &lumberjack.Logger{
MaxSize: 200,
LocalTime: true,
Compress: true,
}
}