Skip to content

Commit

Permalink
feat(server): cmd flag to disable colored logs (backport cosmos#18478) (
Browse files Browse the repository at this point in the history
cosmos#18508)

Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
2 people authored and emidev98 committed Mar 21, 2024
1 parent dc47405 commit d9c494d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions server/cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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}

Expand Down

0 comments on commit d9c494d

Please sign in to comment.