修改配置

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

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

Loading…
Cancel
Save