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

slog: failed to handle log, error: write ./logs/info.log: file already closed #144

Open qmdx opened 4 months ago

qmdx commented 4 months ago

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")
}
qmdx commented 2 months ago

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

inhere commented 2 months ago

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

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