增加了日志记录级别配置

main
cc 2024-07-20 07:56:58 +00:00
parent 68a95cf351
commit 4b754a0164
2 changed files with 12 additions and 1 deletions

View File

@ -1,5 +1,15 @@
package zaplog package zaplog
const (
Debug int8 = iota - 1
Info
Warn
Error
DPanic
Panic
Fatal
)
type LogFileConfig struct { type LogFileConfig struct {
Filename string // 日志文件存放目录及名称,如果文件夹不存在会自动创建 Filename string // 日志文件存放目录及名称,如果文件夹不存在会自动创建
FileSize_MB int // 文件大小限制,单位MB FileSize_MB int // 文件大小限制,单位MB
@ -9,6 +19,7 @@ type LogFileConfig struct {
type ZapConfig struct { type ZapConfig struct {
JsonFormat bool // 是否使用json格式,默认false JsonFormat bool // 是否使用json格式,默认false
Mode int8 // 日志启用级别
DebugLog LogFileConfig // Debug日志配置 DebugLog LogFileConfig // Debug日志配置
InfoLog LogFileConfig // Info日志配置 InfoLog LogFileConfig // Info日志配置
WarnLog LogFileConfig // Warn日志配置 WarnLog LogFileConfig // Warn日志配置

View File

@ -129,5 +129,5 @@ func New(config ...ZapConfig) *zap.SugaredLogger {
HighFileCore := zapcore.NewCore(encoder, zapcore.NewMultiWriteSyncer(HighFileWriteSyncer, zapcore.AddSync(os.Stdout)), HighPriority) HighFileCore := zapcore.NewCore(encoder, zapcore.NewMultiWriteSyncer(HighFileWriteSyncer, zapcore.AddSync(os.Stdout)), HighPriority)
coreArr = append(coreArr, HighFileCore) coreArr = append(coreArr, HighFileCore)
return zap.New(zapcore.NewTee(coreArr...)).Sugar() return zap.New(zapcore.NewTee(coreArr...), zap.IncreaseLevel(zapcore.Level(cfg.Mode))).Sugar()
} }