Skip to content

Commit

Permalink
feat(log): add switch for colorful logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Akegarasu committed Nov 14, 2021
1 parent e924fc5 commit 77580ae
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions internal/base/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
ReportSelfMessage bool // 是否上报自身消息
UseSSOAddress bool // 是否使用服务器下发的新地址进行重连
LogForceNew bool // 是否在每次启动时强制创建全新的文件储存日志
LogColorful bool // 是否启用日志颜色
FastStart bool // 是否为快速启动

PostFormat string // 上报格式 string or array
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)...))

Expand Down
1 change: 1 addition & 0 deletions modules/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
2 changes: 2 additions & 0 deletions modules/config/default_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ output:
log-aging: 15
# 是否在每次启动时强制创建全新的文件储存日志. 为 false 的情况下将会在上次启动时创建的日志文件续写
log-force-new: true
# 是否启用日志颜色
log-colorful: true
# 是否启用 DEBUG
debug: false # 开启调试模式

Expand Down

0 comments on commit 77580ae

Please sign in to comment.