Skip to content

Commit

Permalink
chore(log): add loglevel flag and fix some debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
bostrt committed Jun 30, 2022
1 parent d11912b commit 3229b8a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 13 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/vmware-tanzu/sonobuoy/cmd/sonobuoy/app"
Expand Down Expand Up @@ -33,12 +34,22 @@ var rootCmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
var err error

// Validate logging level
loglevel := viper.GetString("loglevel")
logrusLevel, err := log.ParseLevel(loglevel)
if err != nil {
return err
}
log.SetLevel(logrusLevel)

// Prepare kube client config
config.Kubeconfig = viper.GetString("kubeconfig")
config.ClientConfig, err = clientcmd.BuildConfigFromFlags("", config.Kubeconfig)
if err != nil {
return err
}

// Prepare sonobuoy client
skc, err := sonodynamic.NewAPIHelperFromRESTConfig(config.ClientConfig)
if err != nil {
return errors.Wrap(err, "couldn't get sonobuoy api helper")
Expand All @@ -63,7 +74,9 @@ func init() {
cobra.OnInitialize(initConfig)

rootCmd.PersistentFlags().String("kubeconfig", "", "kubeconfig for target OpenShift cluster")
rootCmd.PersistentFlags().String("loglevel", "info", "logging level")
viper.BindPFlag("kubeconfig", rootCmd.PersistentFlags().Lookup("kubeconfig"))
viper.BindPFlag("loglevel", rootCmd.PersistentFlags().Lookup("loglevel"))

// Link in child commands
rootCmd.AddCommand(destroy.NewCmdDestroy(config))
Expand Down
6 changes: 3 additions & 3 deletions pkg/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ func (r *RunOptions) Run() error {

if r.plugins == nil || len(*r.plugins) == 0 {
// Use default built-in plugins
log.Trace("Loading default certification plugins")
log.Debugf("Loading default certification plugins")
for _, m := range defaultPlugins {
log.Trace("Loading certification plugin: %s", m)
log.Debugf("Loading certification plugin: %s", m)
asset, err := loader.LoadDefinition(assets.MustAsset(m))
if err != nil {
return err
Expand All @@ -218,7 +218,7 @@ func (r *RunOptions) Run() error {
}
} else {
// User provided their own plugins at command line
log.Trace("Loading plugins specific at command line")
log.Debugf("Loading plugins specific at command line")
for _, p := range *r.plugins {
asset, err := loader.LoadDefinitionFromFile(p)
if err != nil {
Expand Down

0 comments on commit 3229b8a

Please sign in to comment.