From e924fc52812e6280195d783550bf605ab8dc4fb0 Mon Sep 17 00:00:00 2001 From: Akiba <36563862+Akegarasu@users.noreply.github.com> Date: Mon, 15 Nov 2021 02:02:34 +0800 Subject: [PATCH 1/3] chore(log): change default logging color --- global/log_hook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global/log_hook.go b/global/log_hook.go index b52181c..b93f130 100644 --- a/global/log_hook.go +++ b/global/log_hook.go @@ -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" ) From 77580ae8ef2b95ae5de581a78a5697f9f7eba515 Mon Sep 17 00:00:00 2001 From: Akiba <36563862+Akegarasu@users.noreply.github.com> Date: Mon, 15 Nov 2021 02:04:04 +0800 Subject: [PATCH 2/3] feat(log): add switch for colorful logging --- internal/base/flag.go | 2 ++ main.go | 2 +- modules/config/config.go | 1 + modules/config/default_config.yml | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/base/flag.go b/internal/base/flag.go index 05f38e4..8cc0ab6 100644 --- a/internal/base/flag.go +++ b/internal/base/flag.go @@ -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" diff --git a/main.go b/main.go index eea53ba..8dd8baa 100644 --- a/main.go +++ b/main.go @@ -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)...)) diff --git a/modules/config/config.go b/modules/config/config.go index 72a39b0..8d4687f 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -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"` diff --git a/modules/config/default_config.yml b/modules/config/default_config.yml index abd2382..50570a5 100644 --- a/modules/config/default_config.yml +++ b/modules/config/default_config.yml @@ -49,6 +49,8 @@ output: log-aging: 15 # 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写 log-force-new: true + # 是否启用日志颜色 + log-colorful: true # 是否启用 DEBUG debug: false # 开启调试模式 From 4de5efc8137c6a3858d1fbc441e1b9aab2e256cd Mon Sep 17 00:00:00 2001 From: Akiba Date: Mon, 15 Nov 2021 11:13:08 +0800 Subject: [PATCH 3/3] fmt --- modules/config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/config/config.go b/modules/config/config.go index 8d4687f..db9571c 100644 --- a/modules/config/config.go +++ b/modules/config/config.go @@ -61,7 +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"` + LogColorful *bool `yaml:"log-colorful"` Debug bool `yaml:"debug"` } `yaml:"output"`