1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-06-19 05:55:04 +08:00

Merge pull request #1163 from Akegarasu/color

feat(log): add switch for colorful logging && change default logging color
This commit is contained in:
Mrs4s 2021-11-16 00:44:39 +08:00 committed by GitHub
commit c8d46d575f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 8 additions and 3 deletions

View File

@ -204,8 +204,8 @@ const (
colorCodeFatal = "\x1b[1;31m" // color.Style{color.Bold, color.Red}.String()
colorCodeError = "\x1b[31m" // color.Style{color.Red}.String()
colorCodeWarn = "\x1b[33m" // color.Style{color.Yellow}.String()
colorCodeInfo = "\x1b[32m" // color.Style{color.Green}.String()
colorCodeDebug = "\x1b[37m" // color.Style{color.White}.String()
colorCodeInfo = "\x1b[37m" // color.Style{color.White}.String()
colorCodeDebug = "\x1b[32m" // color.Style{color.Green}.String()
colorCodeTrace = "\x1b[36m" // color.Style{color.Cyan}.String()
colorReset = "\x1b[0m"
)

View File

@ -37,6 +37,7 @@ var (
ReportSelfMessage bool // 是否上报自身消息
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
LogColorful bool // 是否启用日志颜色
FastStart bool // 是否为快速启动
PostFormat string // 上报格式 string or array
@ -92,6 +93,7 @@ func Init() {
Servers = conf.Servers
Database = conf.Database
LogLevel = conf.Output.LogLevel
LogColorful = conf.Output.LogColorful == nil || *conf.Output.LogColorful
if conf.Message.PostFormat != "string" && conf.Message.PostFormat != "array" {
log.Warnf("post-format 配置错误, 将自动使用 string")
PostFormat = "string"

View File

@ -77,7 +77,7 @@ func main() {
panic(err)
}
consoleFormatter := global.LogFormat{EnableColor: true}
consoleFormatter := global.LogFormat{EnableColor: base.LogColorful}
fileFormatter := global.LogFormat{EnableColor: false}
log.AddHook(global.NewLocalHook(w, consoleFormatter, fileFormatter, global.GetLogLevel(base.LogLevel)...))

View File

@ -61,6 +61,7 @@ type Config struct {
LogLevel string `yaml:"log-level"`
LogAging int `yaml:"log-aging"`
LogForceNew bool `yaml:"log-force-new"`
LogColorful *bool `yaml:"log-colorful"`
Debug bool `yaml:"debug"`
} `yaml:"output"`

View File

@ -49,6 +49,8 @@ output:
log-aging: 15
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
log-force-new: true
# 是否启用日志颜色
log-colorful: true
# 是否启用 DEBUG
debug: false # 开启调试模式