Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): parse module log-levels #3285

Merged
merged 2 commits into from
May 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 77 additions & 22 deletions cmd/gossamer/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,6 @@ var (
pruning string
telemetryURLs string

// Log Config
logLevelCore string
logLevelDigest string
logLevelSync string
logLevelNetwork string
logLevelRPC string
logLevelState string
logLevelRuntime string
logLevelBABE string
logLevelGRANDPA string

// Core Config
// role of the node. one of: full, light or authority
role string
Expand Down Expand Up @@ -173,7 +162,9 @@ func addRootFlags(cmd *cobra.Command) error {
}

// Log Config
addLogFlags(cmd)
if err := addLogFlags(cmd); err != nil {
return fmt.Errorf("failed to add log flags: %s", err)
}

// Account Config
if err := addAccountFlags(cmd); err != nil {
Expand Down Expand Up @@ -270,16 +261,80 @@ Expected format is 'URL VERBOSITY', e.g. ''--telemetry-url wss://foo/bar:0, wss:
}

// addLogFlags adds the log flags to the command
func addLogFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&logLevelCore, "lcore", config.Log.Core, "Core module log level")
cmd.Flags().StringVar(&logLevelDigest, "ldigest", config.Log.Digest, "Digest module log level")
cmd.Flags().StringVar(&logLevelSync, "lsync", config.Log.Sync, "Sync module log level")
cmd.Flags().StringVar(&logLevelNetwork, "lnetwork", config.Log.Network, "Network module log level")
cmd.Flags().StringVar(&logLevelRPC, "lrpc", config.Log.RPC, "RPC module log level")
cmd.Flags().StringVar(&logLevelState, "lstate", config.Log.State, "State module log level")
cmd.Flags().StringVar(&logLevelRuntime, "lruntime", config.Log.Runtime, "Runtime module log level")
cmd.Flags().StringVar(&logLevelBABE, "lbabe", config.Log.Babe, "BABE module log level")
cmd.Flags().StringVar(&logLevelGRANDPA, "lgrandpa", config.Log.Grandpa, "GRANDPA module log level")
func addLogFlags(cmd *cobra.Command) error {
if err := addStringFlagBindViper(cmd,
"lcore",
config.Log.Core,
"Core module log level",
"log.core"); err != nil {
return fmt.Errorf("failed to add --lcore flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"ldigest",
config.Log.Digest,
"Digest module log level",
"log.digest"); err != nil {
return fmt.Errorf("failed to add --ldigest flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lsync",
config.Log.Sync,
"Sync module log level",
"log.sync"); err != nil {
return fmt.Errorf("failed to add --lsync flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lnetwork",
config.Log.Network,
"Network module log level",
"log.network"); err != nil {
return fmt.Errorf("failed to add --lnetwork flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lrpc",
config.Log.RPC,
"RPC module log level",
"log.rpc"); err != nil {
return fmt.Errorf("failed to add --lrpc flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lstate",
config.Log.State,
"State module log level",
"log.state"); err != nil {
return fmt.Errorf("failed to add --lstate flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lruntime",
config.Log.Runtime,
"Runtime module log level",
"log.runtime"); err != nil {
return fmt.Errorf("failed to add --lruntime flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lbabe",
config.Log.Babe,
"BABE module log level",
"log.babe"); err != nil {
return fmt.Errorf("failed to add --lbabe flag: %s", err)
}

if err := addStringFlagBindViper(cmd,
"lgrandpa",
config.Log.Grandpa,
"GRANDPA module log level",
"log.grandpa"); err != nil {
return fmt.Errorf("failed to add --lgrandpa flag: %s", err)
}

return nil
}

// addAccountFlags adds account flags and binds to viper
Expand Down