gookit / slog

📑 Lightweight, configurable, extensible logging library written in Go. Support multi level, multi outputs and built-in multi file logger, buffers, clean, rotate-file handling.一个易于使用的,轻量级、可配置、可扩展的日志库。支持多个级别,输出到多文件;内置文件日志处理、自动切割、清理、压缩等增强功能
https://pkg.go.dev/github.com/gookit/slog
MIT License
383 stars 24 forks source link

[Bug] RotateTime.level() #121

Open ly020044 opened 11 months ago

ly020044 commented 11 months ago

System (please complete the following information):

Describe the bug

当我配置按日期的方式来滚动日志时,当大于 1 天时只能按 1 天来滚动日志。

To Reproduce

seconds := 604800 // 7天
handler.NewTimeRotateFileHandler(
        logFile,
        rotatefile.RotateTime(seconds),
        handler.WithLogLevels(parseLevels(log.level)),
        handler.WithBuffSize(log.bufferSize),
        handler.WithBackupNum(log.maxBackups),
        handler.WithCompress(log.compress),
        handler.WithFilePerm(log.filePerm),

请查看一下这个方法 RotateTime.level

inhere commented 9 months ago

看了代码,感觉没问题啊。第一次是按当天的结束时间开始切,下一次是在 curTime + checkInterval(= 604800) 时切割处理。

iredmail commented 6 months ago

实际生产环境:设置了备份间隔为1星期,再加上 rotate backup 为 20(保留20个 rotate 之后的log文件),但实际有且只有一个 rotate 后的 log 文件。