From 570d19ddb086939e2dfeedc4990975c4101d9162 Mon Sep 17 00:00:00 2001 From: zakir Date: Tue, 25 Oct 2022 14:10:04 +0800 Subject: [PATCH] fix: '--log_filter' flag --- app/cli/log_filter.go | 17 ----------------- cmd/root.go | 29 +++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/cli/log_filter.go b/app/cli/log_filter.go index 759133d..bc099ee 100644 --- a/app/cli/log_filter.go +++ b/app/cli/log_filter.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/spf13/cobra" - "github.com/cosmos/cosmos-sdk/server" tmlog "github.com/tendermint/tendermint/libs/log" ) @@ -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 { diff --git a/cmd/root.go b/cmd/root.go index 8b84a70..bb0760e 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -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 { @@ -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", @@ -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(), @@ -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