Skip to content

Commit

Permalink
refactor: default logger. log to stdout
Browse files Browse the repository at this point in the history
disable colored output by default

Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Apr 25, 2023
1 parent ebbac57 commit 31a8fd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions cmd/akash/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func Execute(rootCmd *cobra.Command, envPrefix string) error {

rootCmd.PersistentFlags().String(flags.FlagLogLevel, zerolog.InfoLevel.String(), "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(utilcli.FlagLogColor, false, "Pretty logging output. Applied only when log_format=plain")

executor := tmcli.PrepareBaseCmd(rootCmd, envPrefix, app.DefaultHome)
return executor.ExecuteContext(ctx)
Expand Down
20 changes: 15 additions & 5 deletions util/cli/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ import (
"strings"
"time"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/config"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"

tmcfg "github.com/tendermint/tendermint/config"

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

const (
FlagLogColor = "log_color"
)

var (
Expand Down Expand Up @@ -67,9 +73,13 @@ func InterceptConfigsPreRunHandler(cmd *cobra.Command, envPrefixes []string, all

var logWriter io.Writer
if strings.ToLower(serverCtx.Viper.GetString(flags.FlagLogFormat)) == tmcfg.LogFormatPlain {
logWriter = zerolog.ConsoleWriter{Out: os.Stderr}
if serverCtx.Viper.GetBool(FlagLogColor) {
logWriter = zerolog.ConsoleWriter{Out: os.Stdout}
} else {
logWriter = zerolog.New(os.Stdout)
}
} else {
logWriter = os.Stderr
logWriter = os.Stdout
}

logLvlStr := serverCtx.Viper.GetString(flags.FlagLogLevel)
Expand Down

0 comments on commit 31a8fd5

Please sign in to comment.