修改配置

master v1.0.1
杨赟 2 years ago
parent fd80391076
commit 9c02fe6be9

@ -55,6 +55,7 @@ type LoggerConfig struct {
Format string `json:"format"` Format string `json:"format"`
EncodeLevel zapcore.LevelEncoder `json:"encodeLevel"` EncodeLevel zapcore.LevelEncoder `json:"encodeLevel"`
Prefix string `json:"prefix"` Prefix string `json:"prefix"`
MaxAge uint `json:"maxAge"`
} }
// InitLogger @Title 初始化日志工具 // InitLogger @Title 初始化日志工具
@ -138,11 +139,16 @@ func (l *logger) pathExists(path string) (bool, error) {
} }
func (l *logger) getWriteSyncer() (zapcore.WriteSyncer, error) { func (l *logger) getWriteSyncer() (zapcore.WriteSyncer, error) {
fileWriter, err := zaprotatelogs.New( options := []zaprotatelogs.Option{
path.Join(l.Config.Director, "%Y-%m-%d.log"),
zaprotatelogs.WithLinkName(l.Config.LinkName), zaprotatelogs.WithLinkName(l.Config.LinkName),
zaprotatelogs.WithMaxAge(time.Hour*24*7),
zaprotatelogs.WithRotationTime(time.Hour * 24), zaprotatelogs.WithRotationTime(time.Hour * 24),
}
if l.Config.MaxAge > 0 {
options = append(options, zaprotatelogs.WithMaxAge(time.Hour*24*time.Duration(l.Config.MaxAge)))
}
fileWriter, err := zaprotatelogs.New(
path.Join(l.Config.Director, "%Y-%m-%d.log"),
options...,
) )
if l.Config.LogInConsole { if l.Config.LogInConsole {
return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err return zapcore.NewMultiWriteSyncer(zapcore.AddSync(os.Stdout), zapcore.AddSync(fileWriter)), err

Loading…
Cancel
Save