From debb6ab99c288948eaa001f93f09df96f67df4b3 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 Nov 2023 18:45:14 +0100 Subject: [PATCH 1/9] feat(server): cmd flag to disable colored logs --- client/flags/flags.go | 1 + server/cmd/execute.go | 1 + server/util.go | 6 +++--- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index d939fabb6715..2b09f4f5e280 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -88,6 +88,7 @@ const ( // Logging flags FlagLogLevel = "log_level" FlagLogFormat = "log_format" + FlagColorLogs = "log_colored" ) // List of supported output formats diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 874fc51cc102..8da0417775b2 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.FlagColorLogs, false, "Enable colored logs") executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx) diff --git a/server/util.go b/server/util.go index 8af5776d1f90..14ec378a504e 100644 --- a/server/util.go +++ b/server/util.go @@ -173,6 +173,9 @@ 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.FlagColorLogs)), + log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag // check and set filter level or keys for the logger if any logLvlStr := ctx.Viper.GetString(flags.FlagLogLevel) @@ -194,9 +197,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 } From c62d5a16f4b9c2dffac91aa31d5842d861149e59 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 Nov 2023 22:48:48 +0100 Subject: [PATCH 2/9] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2803cd8ed97b..630c1d317b2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (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. +* (server) [#18478](https://github.com/cosmos/cosmos-sdk/pull/18478) CMD flag to disable colored logs. ### Improvements From 557080096b48590bb7e4a04d9feb5d42bbc91d7f Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 Nov 2023 22:49:41 +0100 Subject: [PATCH 3/9] rename flag --- client/flags/flags.go | 6 +++--- server/cmd/execute.go | 2 +- server/util.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index 2b09f4f5e280..fb403503f77e 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -86,9 +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" - FlagColorLogs = "log_colored" + FlagLogLevel = "log_level" + FlagLogFormat = "log_format" + FlagLogColored = "log_colored" ) // List of supported output formats diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 8da0417775b2..296ed1ebbde2 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -28,7 +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.FlagColorLogs, false, "Enable colored logs") + rootCmd.PersistentFlags().Bool(flags.FlagLogColored, false, "Enable colored logs") executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx) diff --git a/server/util.go b/server/util.go index 14ec378a504e..421b11119693 100644 --- a/server/util.go +++ b/server/util.go @@ -174,7 +174,7 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(ctx.Viper.GetBool(flags.FlagColorLogs)), + log.ColorOption(ctx.Viper.GetBool(flags.FlagLogColored)), log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag // check and set filter level or keys for the logger if any From b5e39d5e0e69fc049f5ce2e1d1511fd567645691 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Wed, 15 Nov 2023 22:52:37 +0100 Subject: [PATCH 4/9] add comment about CometBFT Trace flag --- server/util.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index 421b11119693..8b66f70a21f1 100644 --- a/server/util.go +++ b/server/util.go @@ -175,7 +175,8 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { } opts = append(opts, log.ColorOption(ctx.Viper.GetBool(flags.FlagLogColored)), - log.TraceOption(ctx.Viper.GetBool("trace"))) // cmtcli.TraceFlag + // 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) From 340614b01a620bfe81e263c614ae2f68558672f2 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 17 Nov 2023 15:17:54 +0100 Subject: [PATCH 5/9] update comment --- server/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index 8b66f70a21f1..f9c1831d15c6 100644 --- a/server/util.go +++ b/server/util.go @@ -175,7 +175,7 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { } opts = append(opts, log.ColorOption(ctx.Viper.GetBool(flags.FlagLogColored)), - // CometBFT flag (cmtcli.TraceFlag) for trace logging. + // 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 From 17020cc79989f7f1e3d9718a829aad77ab500b3d Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 17 Nov 2023 15:20:21 +0100 Subject: [PATCH 6/9] rename flag --- client/flags/flags.go | 6 +++--- server/cmd/execute.go | 2 +- server/util.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index fb403503f77e..b990252840cb 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -86,9 +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" - FlagLogColored = "log_colored" + FlagLogLevel = "log_level" + FlagLogFormat = "log_format" + FlagLogNotColored = "log_not_colored" ) // List of supported output formats diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 296ed1ebbde2..55651438988c 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -28,7 +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.FlagLogColored, false, "Enable colored logs") + rootCmd.PersistentFlags().Bool(flags.FlagLogNotColored, 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 f9c1831d15c6..d8fe8de568d1 100644 --- a/server/util.go +++ b/server/util.go @@ -174,7 +174,7 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(ctx.Viper.GetBool(flags.FlagLogColored)), + log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNotColored)), // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. log.TraceOption(ctx.Viper.GetBool(FlagTrace))) From 7809c4c5de2f631cb7936af8b20c6bc968a77ffa Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 17 Nov 2023 19:31:38 +0100 Subject: [PATCH 7/9] simplify name --- client/flags/flags.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/flags/flags.go b/client/flags/flags.go index b990252840cb..26a93a5e6e2f 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -86,9 +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" - FlagLogNotColored = "log_not_colored" + FlagLogLevel = "log_level" + FlagLogFormat = "log_format" + FlagLogNoColor = "log_no_color" ) // List of supported output formats From ff6d836b49e3942bb0433f98033fc9b79ed7f103 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 17 Nov 2023 22:08:16 +0100 Subject: [PATCH 8/9] fix compile --- server/util.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/util.go b/server/util.go index d8fe8de568d1..beaf6c554dbc 100644 --- a/server/util.go +++ b/server/util.go @@ -174,7 +174,7 @@ func CreateSDKLogger(ctx *Context, out io.Writer) (log.Logger, error) { opts = append(opts, log.OutputJSONOption()) } opts = append(opts, - log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNotColored)), + log.ColorOption(!ctx.Viper.GetBool(flags.FlagLogNoColor)), // We use CometBFT flag (cmtcli.TraceFlag) for trace logging. log.TraceOption(ctx.Viper.GetBool(FlagTrace))) From 04e9d94a8d8200891c50baa904b51b6d5a03ffb5 Mon Sep 17 00:00:00 2001 From: Robert Zaremba Date: Fri, 17 Nov 2023 22:10:38 +0100 Subject: [PATCH 9/9] forgot to save --- server/cmd/execute.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/cmd/execute.go b/server/cmd/execute.go index 55651438988c..cf8e7c009f44 100644 --- a/server/cmd/execute.go +++ b/server/cmd/execute.go @@ -28,7 +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.FlagLogNotColored, false, "Disable colored logs") + rootCmd.PersistentFlags().Bool(flags.FlagLogNoColor, false, "Disable colored logs") executor := cmtcli.PrepareBaseCmd(rootCmd, envPrefix, defaultHome) return executor.ExecuteContext(ctx)