|
|
@ -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) {
|
|
|
|
|
|
|
|
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(
|
|
|
|
fileWriter, err := zaprotatelogs.New(
|
|
|
|
path.Join(l.Config.Director, "%Y-%m-%d.log"),
|
|
|
|
path.Join(l.Config.Director, "%Y-%m-%d.log"),
|
|
|
|
zaprotatelogs.WithLinkName(l.Config.LinkName),
|
|
|
|
options...,
|
|
|
|
zaprotatelogs.WithMaxAge(time.Hour*24*7),
|
|
|
|
|
|
|
|
zaprotatelogs.WithRotationTime(time.Hour*24),
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
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
|
|
|
|