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 #18478

Merged
merged 10 commits into from
Nov 19, 2023
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (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.

### Improvements

Expand Down
5 changes: 3 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions server/cmd/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"

Check failure on line 12 in server/cmd/execute.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/cosmos/cosmos-sdk/server (-: # github.com/cosmos/cosmos-sdk/server
)

// Execute executes the root command of an application. It handles creating a
Expand All @@ -28,6 +28,7 @@
rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "The logging level (trace|debug|info|warn|error|fatal|panic|disabled or '*:<level>,<key>:<level>')")
// 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.FlagLogNotColored, false, "Disable colored logs")

Check failure on line 31 in server/cmd/execute.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: flags.FlagLogNotColored

Check failure on line 31 in server/cmd/execute.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: flags.FlagLogNotColored (typecheck)

executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome)
return executor.ExecuteContext(ctx)
Expand Down
7 changes: 4 additions & 3 deletions server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@
if ctx.Viper.GetString(flags.FlagLogFormat) == flags.OutputFormatJSON {
opts = append(opts, log.OutputJSONOption())
}
opts = append(opts,
log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNotColored)),

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / dependency-review

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (03)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (00)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (01)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / tests (02)

undefined: flags.FlagLogNotColored

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: flags.FlagLogNotColored) (typecheck)

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: flags.FlagLogNotColored) (typecheck)

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: flags.FlagLogNotColored) (typecheck)

Check failure on line 177 in server/util.go

View workflow job for this annotation

GitHub Actions / golangci-lint

undefined: flags.FlagLogNotColored) (typecheck)
// We use CometBFT flag (cmtcli.TraceFlag) for trace logging.
log.TraceOption(ctx.Viper.GetBool(FlagTrace)))
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

// check and set filter level or keys for the logger if any
logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel)
Expand All @@ -194,9 +198,6 @@
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
}

Expand Down
Loading