Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slog 运行时不会限制备份数量和压缩备份文件 #111

Closed
ly020044 opened this issue Jul 27, 2023 · 3 comments
Closed

slog 运行时不会限制备份数量和压缩备份文件 #111

ly020044 opened this issue Jul 27, 2023 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@ly020044
Copy link

ly020044 commented Jul 27, 2023

System (please complete the following information):

  • OS: macOS
  • GO Version: 1.21
  • Pkg Version: 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
截屏2023-07-27 09 21 11

@inhere inhere added the bug Something isn't working label Jul 27, 2023
@inhere
Copy link
Member

inhere commented Jul 27, 2023

感谢报告,我测试一下

@inhere
Copy link
Member

inhere commented Jul 28, 2023

有个BUG修复了,可以拉取最新版本试试。

iredmail added a commit to iredmail/goutils that referenced this issue Jul 28, 2023
@ly020044
Copy link
Author

辛苦了,测试可以了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants