mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 19:43:49 +08:00
feat: log aging & force new log file. close #963
This commit is contained in:
parent
b68bb0762f
commit
85df77f9a5
@ -56,8 +56,10 @@ type Config struct {
|
||||
} `yaml:"message"`
|
||||
|
||||
Output struct {
|
||||
LogLevel string `yaml:"log-level"`
|
||||
Debug bool `yaml:"debug"`
|
||||
LogLevel string `yaml:"log-level"`
|
||||
LogAging int `yaml:"log-aging"`
|
||||
LogForceNew bool `yaml:"log-force-new"`
|
||||
Debug bool `yaml:"debug"`
|
||||
} `yaml:"output"`
|
||||
|
||||
Servers []map[string]yaml.Node `yaml:"servers"`
|
||||
|
@ -43,6 +43,10 @@ message:
|
||||
output:
|
||||
# 日志等级 trace,debug,info,warn,error
|
||||
log-level: warn
|
||||
# 日志时效 单位天. 超过这个时间之前的日志将会被自动删除. 设置为 0 表示永久保留.
|
||||
log-aging: 15
|
||||
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
|
||||
log-force-new: true
|
||||
# 是否启用 DEBUG
|
||||
debug: false # 开启调试模式
|
||||
|
||||
|
16
main.go
16
main.go
@ -75,13 +75,25 @@ func init() {
|
||||
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
||||
}
|
||||
|
||||
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotatelogs.WithRotationTime(time.Hour*24))
|
||||
conf = config.Get()
|
||||
|
||||
rotateOptions := []rotatelogs.Option{
|
||||
rotatelogs.WithRotationTime(time.Hour * 24),
|
||||
}
|
||||
|
||||
if conf.Output.LogAging > 0 {
|
||||
rotateOptions = append(rotateOptions, rotatelogs.WithMaxAge(time.Hour*24*time.Duration(conf.Output.LogAging)))
|
||||
}
|
||||
if conf.Output.LogForceNew {
|
||||
rotateOptions = append(rotateOptions, rotatelogs.ForceNewFile())
|
||||
}
|
||||
|
||||
w, err := rotatelogs.New(path.Join("logs", "%Y-%m-%d.log"), rotateOptions...)
|
||||
if err != nil {
|
||||
log.Errorf("rotatelogs init err: %v", err)
|
||||
panic(err)
|
||||
}
|
||||
|
||||
conf = config.Get()
|
||||
if debug {
|
||||
conf.Output.Debug = true
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user