mirror of
https://github.com/Mrs4s/go-cqhttp.git
synced 2025-05-05 03:23:49 +08:00
feat(log): add switch for colorful logging
This commit is contained in:
parent
e924fc5281
commit
77580ae8ef
@ -37,6 +37,7 @@ var (
|
|||||||
ReportSelfMessage bool // 是否上报自身消息
|
ReportSelfMessage bool // 是否上报自身消息
|
||||||
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
|
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
|
||||||
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
|
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
|
||||||
|
LogColorful bool // 是否启用日志颜色
|
||||||
FastStart bool // 是否为快速启动
|
FastStart bool // 是否为快速启动
|
||||||
|
|
||||||
PostFormat string // 上报格式 string or array
|
PostFormat string // 上报格式 string or array
|
||||||
@ -92,6 +93,7 @@ func Init() {
|
|||||||
Servers = conf.Servers
|
Servers = conf.Servers
|
||||||
Database = conf.Database
|
Database = conf.Database
|
||||||
LogLevel = conf.Output.LogLevel
|
LogLevel = conf.Output.LogLevel
|
||||||
|
LogColorful = conf.Output.LogColorful == nil || *conf.Output.LogColorful
|
||||||
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
|
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
|
||||||
log.Warnf("post-format 配置错误, 将自动使用 string")
|
log.Warnf("post-format 配置错误, 将自动使用 string")
|
||||||
PostFormat = "string"
|
PostFormat = "string"
|
||||||
|
2
main.go
2
main.go
@ -77,7 +77,7 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
consoleFormatter := global.LogFormat{EnableColor: true}
|
consoleFormatter := global.LogFormat{EnableColor: base.LogColorful}
|
||||||
fileFormatter := global.LogFormat{EnableColor: false}
|
fileFormatter := global.LogFormat{EnableColor: false}
|
||||||
log.AddHook(global.NewLocalHook(w, consoleFormatter, fileFormatter, global.GetLogLevel(base.LogLevel)...))
|
log.AddHook(global.NewLocalHook(w, consoleFormatter, fileFormatter, global.GetLogLevel(base.LogLevel)...))
|
||||||
|
|
||||||
|
@ -61,6 +61,7 @@ type Config struct {
|
|||||||
LogLevel string `yaml:"log-level"`
|
LogLevel string `yaml:"log-level"`
|
||||||
LogAging int `yaml:"log-aging"`
|
LogAging int `yaml:"log-aging"`
|
||||||
LogForceNew bool `yaml:"log-force-new"`
|
LogForceNew bool `yaml:"log-force-new"`
|
||||||
|
LogColorful *bool `yaml:"log-colorful"`
|
||||||
Debug bool `yaml:"debug"`
|
Debug bool `yaml:"debug"`
|
||||||
} `yaml:"output"`
|
} `yaml:"output"`
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ output:
|
|||||||
log-aging: 15
|
log-aging: 15
|
||||||
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
|
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
|
||||||
log-force-new: true
|
log-force-new: true
|
||||||
|
# 是否启用日志颜色
|
||||||
|
log-colorful: true
|
||||||
# 是否启用 DEBUG
|
# 是否启用 DEBUG
|
||||||
debug: false # 开启调试模式
|
debug: false # 开启调试模式
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user