From debb6ab99c288948eaa001f93f09df96f67df4b3 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 Nov 2023 18:45:14 +0100 Subject: [PATCH] feat(server): cmd flag to disable colored logs --- client/flags/flags.go | 1 + server/cmd/execute.go | 1 + server/util.go | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index d939fabb6715..2b09f4f5e280 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -88,6 +88,7 @@ const ( // Logging flags FlagLogLevel = "log_level" FlagLogFormat = "log_format" + FlagColorLogs = "log_colored" ) // List of supported output formats diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 874fc51cc102..8da0417775b2 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -28,6 +28,7 @@ func Execute(rootCmd *cobra.Command, envPrefix, defaultHome string) error { rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:,:')") // NOTE: The default logger is only checking for the "json" value, any other value will default to plain text. rootCmd.PersistentFlags().String(flags.FlagLogFormat, "plain", "The logging format (json|plain)") + rootCmd.PersistentFlags().Bool(flags.FlagColorLogs, false, "Enable colored logs") executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx) diff --git a/server/util.go b/server/util.go index 8af5776d1f90..14ec378a504e 100644 --- a/server/util.go +++ b/server/util.go @@ -173,6 +173,9 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { if ctx.Viper.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON { opts = append(opts, log.OutputJSONOption()) } + opts = append(opts, + log.ColorOption(ctx.Viper.GetBool(flags.FlagColorLogs)), + log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag // check and set filter level or keys for the logger if any logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) @@ -194,9 +197,6 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { opts = append(opts, log.LevelOption(logLvl)) } - // Check if the CometBFT flag for trace logging is set and enable stack traces if so. - opts = append(opts, log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag - return log.NewLogger(out, opts...), nil }