Closed ly020044 closed 1 year ago
System (please complete the following information):
macOS
1.21
0.5.3
Describe the bug
运行时 slog 不会根据 BackupNum 参数限制文件备份文件的数量,开启压缩选项后在运行过程中也不会将备份的文件进行压缩。 当重新启动后 slog 才会移除多余的备份文件,及压缩备份文件
To Reproduce
以下程序将每隔 30 秒产生一个备份文件,持续 10 分钟。允许的最大备份数据为 5 并开启压缩功能。
package main import ( "context" "fmt" "time" "github.com/gookit/slog" "github.com/gookit/slog/handler" "github.com/gookit/slog/rotatefile" ) const pth = "./logs/main.log" func main() { log := slog.New() h, err := handler.NewTimeRotateFileHandler( pth, rotatefile.RotateTime((time.Second * 30).Seconds()), handler.WithBuffSize(0), handler.WithBackupNum(5), handler.WithCompress(true), ) if err != nil { panic(err) } log.AddHandler(h) ctx, _ := context.WithTimeout(context.Background(), time.Minute*10) go func() { for { select { case <-ctx.Done(): return case <-time.After(time.Second): log.Info("Log " + time.Now().String()) } } }() <-ctx.Done() fmt.Println("Exit.") }
Expected behavior
应该在运行时就限制相应的备份数量及压缩备份文件,而不是在重新启动后。
Screenshots
感谢报告,我测试一下
有个BUG修复了,可以拉取最新版本试试。
辛苦了,测试可以了!
System (please complete the following information):
macOS
1.21
0.5.3
Describe the bug
运行时 slog 不会根据 BackupNum 参数限制文件备份文件的数量,开启压缩选项后在运行过程中也不会将备份的文件进行压缩。 当重新启动后 slog 才会移除多余的备份文件,及压缩备份文件
To Reproduce
以下程序将每隔 30 秒产生一个备份文件,持续 10 分钟。允许的最大备份数据为 5 并开启压缩功能。
Expected behavior
应该在运行时就限制相应的备份数量及压缩备份文件,而不是在重新启动后。
Screenshots