mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-06 03:53:50 +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"`
|
} `yaml:"message"`
|
||||||
|
|
||||||
Output struct {
|
Output struct {
|
||||||
LogLevel string `yaml:"log-level"`
|
LogLevel string `yaml:"log-level"`
|
||||||
Debug bool `yaml:"debug"`
|
LogAging int `yaml:"log-aging"`
|
||||||
|
LogForceNew bool `yaml:"log-force-new"`
|
||||||
|
Debug bool `yaml:"debug"`
|
||||||
} `yaml:"output"`
|
} `yaml:"output"`
|
||||||
|
|
||||||
Servers []map[string]yaml.Node `yaml:"servers"`
|
Servers []map[string]yaml.Node `yaml:"servers"`
|
||||||
|
@ -43,6 +43,10 @@ message:
|
|||||||
output:
|
output:
|
||||||
# 日志等级 trace,debug,info,warn,error
|
# 日志等级 trace,debug,info,warn,error
|
||||||
log-level: warn
|
log-level: warn
|
||||||
|
# 日志时效 单位天. 超过这个时间之前的日志将会被自动删除. 设置为 0 表示永久保留.
|
||||||
|
log-aging: 15
|
||||||
|
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
|
||||||
|
log-force-new: true
|
||||||
# 是否启用 DEBUG
|
# 是否启用 DEBUG
|
||||||
debug: false # 开启调试模式
|
debug: false # 开启调试模式
|
||||||
|
|
||||||
|
16
main.go
16
main.go
@ -75,13 +75,25 @@ func init() {
|
|||||||
LogFormat: "[%time%] [%lvl%]: %msg% \n",
|
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 {
|
if err != nil {
|
||||||
log.Errorf("rotatelogs init err: %v", err)
|
log.Errorf("rotatelogs init err: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf = config.Get()
|
|
||||||
if debug {
|
if debug {
|
||||||
conf.Output.Debug = true
|
conf.Output.Debug = true
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user