You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
785 B
27 lines
785 B
package LogBuilder
|
|
|
|
import (
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"gopkg.in/natefinch/lumberjack.v2"
|
|
)
|
|
|
|
func getEncoder() zapcore.Encoder {
|
|
encoderConfig := zap.NewProductionEncoderConfig()
|
|
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
|
|
encoderConfig.TimeKey = "time"
|
|
encoderConfig.EncodeLevel = zapcore.CapitalLevelEncoder
|
|
encoderConfig.EncodeDuration = zapcore.SecondsDurationEncoder
|
|
encoderConfig.EncodeCaller = zapcore.ShortCallerEncoder
|
|
return zapcore.NewJSONEncoder(encoderConfig)
|
|
}
|
|
|
|
func getLogWriter(filename string, maxSize, maxBackup, maxAge int) zapcore.WriteSyncer {
|
|
lumberJackLogger := &lumberjack.Logger{
|
|
Filename: filename,
|
|
MaxSize: maxSize,
|
|
MaxBackups: maxBackup,
|
|
MaxAge: maxAge,
|
|
}
|
|
return zapcore.AddSync(lumberJackLogger)
|
|
}
|
|
|