Skip to content

Commit

Permalink
root: add --debug option for changing logger level
Browse files Browse the repository at this point in the history
Add the --debug option as a persistent option for setting the LOG_DEBUG
log level.

Signed-off-by: Bruno Meneguele <bmeneg@redhat.com>
  • Loading branch information
bmeneg committed May 14, 2021
1 parent e62e8ff commit 35abd0c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ func init() {
RootCmd.AddCommand(versionCmd)
RootCmd.Flags().Bool("version", false, "Show the lab version")
RootCmd.PersistentFlags().Bool("no-pager", false, "Do not pipe output into a pager")
RootCmd.PersistentFlags().Bool("debug", false, "Enable debug logging level")

// We need to set the logger level before any other piece of code is
// called, thus we make sure we don't lose any debug message, but for
// that we need to parse the args from command input.
err := RootCmd.ParseFlags(os.Args[1:])
// Handle the err != nil case later
if err == nil {
debugLogLevel, _ := RootCmd.Flags().GetBool("debug")
if debugLogLevel {
log.SetLogLevel(logger.LOG_DEBUG)
}
}
}

var (
Expand Down

0 comments on commit 35abd0c

Please sign in to comment.