From 60112c6ab8b74f5ee4d8126d4c0eabc4ae3d786f Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 19 Nov 2023 15:29:22 +0000 Subject: [PATCH] feat(server): cmd flag to disable colored logs (backport #18478) (#18508) Co-authored-by: Julien Robert --- CHANGELOG.md | 4 ++++ client/flags/flags.go | 5 +++-- server/cmd/execute.go | 1 + server/util.go | 8 +++++--- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5230ff3bfca..589168d79e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (server) [#18478](https://github.com/cosmos/cosmos-sdk/pull/18478) Add command flag to disable colored logs. + ### Bug Fixes * (client/tx) [#18472](https://github.com/cosmos/cosmos-sdk/pull/18472) Utilizes the correct Pubkey when simulating a transaction. diff --git a/client/flags/flags.go b/client/flags/flags.go index 51918b473a98..b7cf758237bf 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -85,8 +85,9 @@ const ( FlagOutput = tmcli.OutputFlag // Tendermint logging flags - FlagLogLevel = "log_level" - FlagLogFormat = "log_format" + FlagLogLevel = "log_level" + FlagLogFormat = "log_format" + FlagLogNoColor = "log_no_color" ) // LineBreak can be included in a command list to provide a blank line diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 843cfc0393cb..1f869b1b317b 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -27,6 +27,7 @@ func Execute(rootCmd *cobra.Command, envPrefix string, defaultHome string) error rootCmd.PersistentFlags().String(flags.FlagLogLevel, tmcfg.DefaultLogLevel, "The logging level (trace|debug|info|warn|error|fatal|panic)") rootCmd.PersistentFlags().String(flags.FlagLogFormat, tmcfg.LogFormatPlain, "The logging format (json|plain)") + rootCmd.PersistentFlags().Bool(flags.FlagLogNoColor, false, "Disable colored logs") executor := tmcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx) diff --git a/server/util.go b/server/util.go index 73a90615bfde..98c193ad77e6 100644 --- a/server/util.go +++ b/server/util.go @@ -160,6 +160,11 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s opts = append(opts, log.OutputJSONOption()) } + opts = append(opts, + log.ColorOption(!serverCtx.Viper.GetBool(flags.FlagLogNoColor)), + // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. + log.TraceOption(serverCtx.Viper.GetBool(FlagTrace))) + // check and set filter level or keys for the logger if any logLvlStr := serverCtx.Viper.GetString(flags.FlagLogLevel) if logLvlStr != "" { @@ -178,9 +183,6 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, customAppConfigTemplate s } } - // Check if the CometBFT flag for trace logging is set and enable stack traces if so. - opts = append(opts, log.TraceOption(serverCtx.Viper.GetBool("trace"))) // cmtcli.TraceFlag - logger := log.NewLogger(tmlog.NewSyncWriter(os.Stdout), opts...).With(log.ModuleKey, "server") serverCtx.Logger = serverlog.CometLoggerWrapper{Logger: logger}