Skip to content

Commit

Permalink
chore: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
leovct committed Nov 10, 2023
1 parent f476f61 commit 939f43c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
5 changes: 2 additions & 3 deletions cmd/monitor/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ var MonitorCmd = &cobra.Command{
Short: "Monitor blocks using a JSON-RPC endpoint.",
Long: usage,
Args: cobra.NoArgs,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// By default, remove logs from `polycli monitor`.
verbosityFlag := cmd.Flags().Lookup("verbosity")
if verbosityFlag != nil && !verbosityFlag.Changed {
return util.SetLogLevel(int(util.Silent))
util.SetLogLevel(int(util.Silent))
}
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return checkFlags()
Expand Down
5 changes: 1 addition & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ func NewPolycliCommand() *cobra.Command {
Short: "A Swiss Army knife of blockchain tools.",
Long: "Polycli is a collection of tools that are meant to be useful while building, testing, and running block chain applications.",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := util.SetLogLevel(verbosity); err != nil {
return err
}

util.SetLogLevel(verbosity)
logMode := util.JSON
if pretty {
logMode = util.Console
Expand Down
7 changes: 2 additions & 5 deletions util/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (

// SetLogLevel sets the log level based on the flags.
// https://logging.apache.org/log4j/2.x/manual/customloglevels.html
func SetLogLevel(verbosity int) error {
func SetLogLevel(verbosity int) {
switch {
case verbosity == int(Silent):
zerolog.SetGlobalLevel(zerolog.NoLevel)
Expand All @@ -41,12 +41,9 @@ func SetLogLevel(verbosity int) error {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case verbosity < int(Debug):
zerolog.SetGlobalLevel(zerolog.DebugLevel)
case verbosity < int(Trace):
zerolog.SetGlobalLevel(zerolog.TraceLevel)
default:
return fmt.Errorf("unsupported log level: %d", verbosity)
zerolog.SetGlobalLevel(zerolog.TraceLevel)
}
return nil
}

type LogMode string
Expand Down

0 comments on commit 939f43c

Please sign in to comment.