From 7ce6cb77d01f2eaab4849988c2dceeb9e077bdfb Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Sun, 19 Nov 2023 15:50:18 +0100 Subject: [PATCH] feat(server): cmd flag to disable colored logs (#18478) (cherry picked from commit 8c7e6941171c8b847f38e36ceca4ba4185c4183a) # Conflicts: # CHANGELOG.md --- CHANGELOG.md | 14 ++++++++++++++ client/flags/flags.go | 5 +++-- server/cmd/execute.go | 1 + server/util.go | 7 ++++--- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 809057644030..de75131394ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,23 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Features +<<<<<<< HEAD * (debug) [#18219](https://github.com/cosmos/cosmos-sdk/pull/18219) Add debug commands for application codec types. * (client/keys) [#17639](https://github.com/cosmos/cosmos-sdk/pull/17639) Allows using and saving public keys encoded as base64. * (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add a `shutdown-grace` flag for waiting a given time before exit. +======= +* (x/staking) [#18142](https://github.com/cosmos/cosmos-sdk/pull/18142) Introduce `key_rotation_fee` param to calculate fees while rotating the keys +* (client) [#18101](https://github.com/cosmos/cosmos-sdk/pull/18101) Add a `keyring-default-keyname` in `client.toml` for specifying a default key name, and skip the need to use the `--from` flag when signing transactions. +* (tests) [#17868](https://github.com/cosmos/cosmos-sdk/pull/17868) Added helper method `SubmitTestTx` in testutil to broadcast test txns to test e2e tests. +* (x/protocolpool) [#17657](https://github.com/cosmos/cosmos-sdk/pull/17657) Create a new `x/protocolpool` module that is responsible for handling community pool funds. This module is split out into a new module from x/distribution. +* (client/keys) [#17639](https://github.com/cosmos/cosmos-sdk/pull/17639) Allows using and saving public keys encoded as base64 +* (client) [#17513](https://github.com/cosmos/cosmos-sdk/pull/17513) Allow overwritting `client.toml`. Use `client.CreateClientConfig` in place of `client.ReadFromClientConfig` and provide a custom template and a custom config. +* (x/bank) [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn`, to burn coins. +* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit. +* (x/auth/vesting) [#17810](https://github.com/cosmos/cosmos-sdk/pull/17810) Add the ability to specify a start time for continuous vesting accounts. +* (runtime) [#18475](https://github.com/cosmos/cosmos-sdk/pull/18475) Adds an implementation for core.branch.Service. +* (server) [#18478](https://github.com/cosmos/cosmos-sdk/pull/18478) CMD flag to disable colored logs. +>>>>>>> 8c7e69411 (feat(server): cmd flag to disable colored logs (#18478)) ### Improvements diff --git a/client/flags/flags.go b/client/flags/flags.go index d939fabb6715..26a93a5e6e2f 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -86,8 +86,9 @@ const ( // This differs from FlagOutputDocument that is used to set the output file. FlagOutput = "output" // Logging flags - FlagLogLevel = "log_level" - FlagLogFormat = "log_format" + FlagLogLevel = "log_level" + FlagLogFormat = "log_format" + FlagLogNoColor = "log_no_color" ) // List of supported output formats diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 874fc51cc102..cf8e7c009f44 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.FlagLogNoColor, false, "Disable colored logs") executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx) diff --git a/server/util.go b/server/util.go index f74ec00d6c01..080fa6df78d3 100644 --- a/server/util.go +++ b/server/util.go @@ -173,6 +173,10 @@ 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.FlagLogNoColor)), + // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. + log.TraceOption(ctx.Viper.GetBool(FlagTrace))) // check and set filter level or keys for the logger if any logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) @@ -194,9 +198,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 }