Skip to content

Commit

Permalink
chore: set default polycli monitor verbosity level to silent (#154)
Browse files Browse the repository at this point in the history
* fix: `polycli monitor` default verbosity level

* chore: remove hack

* Revert "chore: remove hack"

This reverts commit 86de636.
  • Loading branch information
leovct authored Nov 10, 2023
1 parent fbd16d4 commit 787261c
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ import (
"github.com/maticnetwork/polygon-cli/cmd/wallet"
)

// VerbosityLevel represents the verbosity levels.
// https://pkg.go.dev/github.com/rs/zerolog#readme-leveled-logging
type VerbosityLevel int

const (
Silent VerbosityLevel = 0
Panic VerbosityLevel = 100
Fatal VerbosityLevel = 200
Error VerbosityLevel = 300
Warn VerbosityLevel = 400
Info VerbosityLevel = 500
Debug VerbosityLevel = 600
Trace VerbosityLevel = 700
)

var (
cfgFile string
verbosity int
Expand Down Expand Up @@ -84,7 +99,11 @@ 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.",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
setLogLevel(verbosity, pretty)
if cmd.Use == monitor.MonitorCmd.Use {
setLogLevel(int(Silent), pretty)
} else {
setLogLevel(verbosity, pretty)
}
},
}

Expand Down Expand Up @@ -123,19 +142,22 @@ func NewPolycliCommand() *cobra.Command {
// setLogLevel sets the log level based on the flags.
// https://logging.apache.org/log4j/2.x/manual/customloglevels.html
func setLogLevel(verbosity int, pretty bool) {
if verbosity < 100 {
switch {
case verbosity == int(Silent):
zerolog.SetGlobalLevel(zerolog.NoLevel)
case verbosity < int(Panic):
zerolog.SetGlobalLevel(zerolog.PanicLevel)
} else if verbosity < 200 {
case verbosity < int(Fatal):
zerolog.SetGlobalLevel(zerolog.FatalLevel)
} else if verbosity < 300 {
case verbosity < int(Error):
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
} else if verbosity < 400 {
case verbosity < int(Warn):
zerolog.SetGlobalLevel(zerolog.WarnLevel)
} else if verbosity < 500 {
case verbosity < int(Info):
zerolog.SetGlobalLevel(zerolog.InfoLevel)
} else if verbosity < 600 {
case verbosity < int(Debug):
zerolog.SetGlobalLevel(zerolog.DebugLevel)
} else {
default:
zerolog.SetGlobalLevel(zerolog.TraceLevel)
}

Expand Down

0 comments on commit 787261c

Please sign in to comment.