Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): cmd flag to disable colored logs (backport #18478) #18508

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading