Skip to content

Commit

Permalink
fix: '--log_filter' flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zakir committed Oct 25, 2022
1 parent e684956 commit 570d19d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
17 changes: 0 additions & 17 deletions app/cli/log_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/server"
tmlog "github.com/tendermint/tendermint/libs/log"
)
Expand All @@ -14,21 +12,6 @@ const (
FlagLogFilter = "log_filter"
)

func AddCmdLogWrapFilterLogType(cmd *cobra.Command) error {
filterLogTypes, err := cmd.Flags().GetStringSlice(FlagLogFilter)
if err != nil {
return err
}
if len(filterLogTypes) <= 0 {
return nil
}
serverCtx := server.GetServerContextFromCmd(cmd)
if zeroLog, ok := serverCtx.Logger.(server.ZeroLogWrapper); ok {
serverCtx.Logger = NewFxZeroLogWrapper(zeroLog, filterLogTypes)
}
return server.SetCmdServerContext(cmd, serverCtx)
}

func NewFxZeroLogWrapper(logger server.ZeroLogWrapper, logTypes []string) FxZeroLogWrapper {
filterLogMap := make(map[string]bool, len(logTypes))
for _, logType := range logTypes {
Expand Down
29 changes: 23 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ import (
otherCli "github.com/pundix/pundix/x/other/client/cli"
)

const envPrefix = "PX"

// NewRootCmd creates a new root command for simd. It is called once in the
// main function.
func NewRootCmd() *cobra.Command {
Expand All @@ -57,7 +59,7 @@ func NewRootCmd() *cobra.Command {
WithAccountRetriever(types.AccountRetriever{}).
WithBroadcastMode(flags.BroadcastBlock).
WithHomeDir(app.DefaultNodeHome).
WithViper("PX")
WithViper(envPrefix)

rootCmd := &cobra.Command{
Use: pxtypes.Name + "d",
Expand Down Expand Up @@ -94,10 +96,9 @@ func NewRootCmd() *cobra.Command {
if err := server.InterceptConfigsPreRunHandler(cmd, config.DefaultConfigTemplate, defConfig); err != nil {
return err
}
return cli.AddCmdLogWrapFilterLogType(cmd)
return nil
},
}
rootCmd.PersistentFlags().StringSlice(cli.FlagLogFilter, nil, `The logging filter can discard custom log type (ABCIQuery)`)
initRootCmd(rootCmd, encodingConfig)
overwriteFlagDefaults(rootCmd, map[string]string{
flags.FlagChainID: pxtypes.ChainId(),
Expand Down Expand Up @@ -140,12 +141,28 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig app.EncodingConfig) {

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
preRun := startCmd.PreRunE
startCmd.Flags().StringSlice(cli.FlagLogFilter, nil, `The logging filter can discard custom log type (ABCIQuery)`)

startCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
if err := preRun(cmd, args); err != nil {
serverCtx := server.GetServerContextFromCmd(cmd)

if zeroLog, ok := serverCtx.Logger.(server.ZeroLogWrapper); ok {
filterLogTypes, _ := cmd.Flags().GetStringSlice(cli.FlagLogFilter)
if len(filterLogTypes) > 0 {
serverCtx.Logger = cli.NewFxZeroLogWrapper(zeroLog, filterLogTypes)
}
}

// Bind flags to the Context's Viper so the app construction can set
// options accordingly.
if err := serverCtx.Viper.BindPFlags(cmd.Flags()); err != nil {
return err
}
serverCtx := server.GetServerContextFromCmd(cmd)

if _, err := server.GetPruningOptionsFromFlags(serverCtx.Viper); err != nil {
return err
}

genesisDoc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
if err != nil {
return err
Expand Down

0 comments on commit 570d19d

Please sign in to comment.