修复日志切割规则构建错误问题

This commit is contained in:
zhangdeman001 2022-06-23 10:23:15 +08:00
parent 3f63f6c673
commit e536831e80

View File

@ -8,9 +8,10 @@
package logger package logger
import ( import (
"time"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
"time"
) )
// InputLogConfig 输入的日志配置 // InputLogConfig 输入的日志配置
@ -21,7 +22,6 @@ import (
type InputLogConfig struct { type InputLogConfig struct {
Name string `json:"name" yaml:"name"` // 日志文件名 Name string `json:"name" yaml:"name"` // 日志文件名
Path string `json:"path" yaml:"path"` // 日志文件路径 Path string `json:"path" yaml:"path"` // 日志文件路径
Format string `json:"format" yaml:"format"` // 文件格式
TimeIntervalType TimeIntervalType `json:"time_interval_type" yaml:"time_interval_type"` // 日志切割规则 TimeIntervalType TimeIntervalType `json:"time_interval_type" yaml:"time_interval_type"` // 日志切割规则
DivisionChar string `json:"division_char" yaml:"division_char"` // 文件名分隔符 DivisionChar string `json:"division_char" yaml:"division_char"` // 文件名分隔符
LogLevel zapcore.Level `json:"log_level" yaml:"log_level"` // 日志等级 LogLevel zapcore.Level `json:"log_level" yaml:"log_level"` // 日志等级
@ -59,14 +59,15 @@ func GetLogInstanceFromInputConfig(logConf *InputLogConfig) (*zap.Logger, error)
var ( var (
err error err error
loggerInstance *zap.Logger loggerInstance *zap.Logger
splitConfig *RotateLogConfig
) )
splitConfig := &RotateLogConfig{ if splitConfig, err = NewRotateLogConfig(
TimeIntervalType: logConf.TimeIntervalType, logConf.Path,
LogPath: logConf.Path, logConf.Name,
LogFileName: logConf.Name, WithDivisionChar(logConf.DivisionChar),
DivisionChar: logConf.DivisionChar, WithTimeIntervalType(logConf.TimeIntervalType),
FullLogFormat: logConf.Format, WithMaxAge(time.Duration(logConf.MaxAge)*time.Second)); nil != err {
MaxAge: time.Duration(logConf.MaxAge) * time.Second, return nil, err
} }
if loggerInstance, err = NewLogger(logConf.LogLevel, splitConfig, logConfList...); nil != err { if loggerInstance, err = NewLogger(logConf.LogLevel, splitConfig, logConfList...); nil != err {
return nil, err return nil, err