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.

28 lines
908 B

package utils
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/natefinch/lumberjack"
"go.uber.org/zap/zapcore"
"os"
)
//@author: [SliverHorn](https://github.com/SliverHorn)
//@function: GetWriteSyncer
//@description: zap logger中加入file-rotatelogs
//@return: zapcore.WriteSyncer, error
func GetWriteSyncer(file string) zapcore.WriteSyncer {
lumberJackLogger := &lumberjack.Logger{
Filename: file, //日志文件的位置
MaxSize: 10, //在进行切割之前,日志文件的最大大小(以MB为单位)
MaxBackups: 200, //保留旧文件的最大个数
MaxAge: 30, //保留旧文件的最大天数
Compress: true, //是否压缩/归档旧文件
}
if global.GVA_CONFIG.Zap.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(lumberJackLogger))
}
return zapcore.AddSync(lumberJackLogger)
}