diff --git a/internal/base/flag.go b/internal/base/flag.go index 05f38e453..8cc0ab6cb 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 eea53ba68..8dd8baa56 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 72a39b0af..8d4687f95 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 abd238293..50570a5f5 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 # 开启调试模式