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: failed to handle log, error: write ./logs/info.log: file already closed #144

Open
qmdx opened this issue Apr 19, 2024 · 3 comments
Open
Assignees
Labels
bug Something isn't working unconfirmed

Comments

@qmdx
Copy link

qmdx commented Apr 19, 2024

windows 自动创建日志目录异常 slog: failed to handle log, error: write ./logs/info.log: file already closed

import (
	"github.com/gookit/slog"
	"github.com/gookit/slog/handler"
	"github.com/gookit/slog/rotatefile"
)

func Slog() {
	defer slog.MustClose()

	// DangerLevels 包含: slog.PanicLevel, slog.ErrorLevel, slog.WarnLevel
	h1 := handler.MustRotateFile("./logs/error.log", rotatefile.EveryDay,
		handler.WithLogLevels(slog.DangerLevels),
		handler.WithCompress(true),
	)

	// NormalLevels 包含: slog.InfoLevel, slog.NoticeLevel, slog.DebugLevel, slog.TraceLevel
	h2 := handler.MustFileHandler("./logs/info.log", handler.WithLogLevels(slog.NormalLevels))

	// 注册 handler 到 logger(调度器)
	slog.PushHandlers(h1, h2)

	// add logs
	slog.Info("info message text")
	slog.Error("error message text")
}
@inhere inhere added the bug Something isn't working label Apr 21, 2024
@qmdx
Copy link
Author

qmdx commented Jul 4, 2024

@inhere 能不能修复下这个 bug 搁置时间有点长哦

@inhere
Copy link
Member

inhere commented Jul 5, 2024

@inhere 能不能修复下这个 bug 搁置时间有点长哦

我mac本地没复现,日志目录和文件有创建吗?运行中突然报错的吗

@inhere
Copy link
Member

inhere commented Sep 14, 2024

我本地用 Windows 测试也没有复现 go1.21。你的 go 版本是多少

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

No branches or pull requests

2 participants