Skip to content

Commit

Permalink
feat: logging levels (#11)
Browse files Browse the repository at this point in the history
* Add logging levels

Signed-off-by: Eytan Avisror <[email protected]>

* Update validate.go

Signed-off-by: Eytan Avisror <[email protected]>
  • Loading branch information
Eytan Avisror authored Jan 24, 2022
1 parent 08055e7 commit 167c7a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/spf13/cobra"
)

const defaultLoggingLevel uint32 = 4

var validateCmd = &cobra.Command{
Use: "validate",
Short: "validate validates a given cluster",
Expand All @@ -42,6 +44,12 @@ var validateCmd = &cobra.Command{
log.Fatalf("failed to create dynamic client: %v", err)
}

if logLevel > 0 && logLevel <= 6 {
log.SetLevel(log.Level(logLevel))
} else {
log.SetLevel(log.Level(defaultLoggingLevel))
}

v := client.NewValidator(c, spec)
err = v.Validate()
if err != nil {
Expand All @@ -52,11 +60,13 @@ var validateCmd = &cobra.Command{

var (
specFile string
logLevel uint32
)

func init() {
rootCmd.AddCommand(validateCmd)
validateCmd.Flags().StringVar(&specFile, "filename", "", "Path to cluster validation manifest file (yaml)")
validateCmd.Flags().Uint32Var(&logLevel, "verbosity", defaultLoggingLevel, "Logging verbosity 1-6")
}

func GetKubernetesConfig() (*rest.Config, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (v *Validator) Validate() error {
} else {
successCount++
failureCount = 0
log.Infof("validation of '%v' successful (%v/%v)", resourceName, successCount, successThreshold)
log.Debugf("validation of '%v' successful (%v/%v)", resourceName, successCount, successThreshold)
}

if successCount >= successThreshold {
Expand Down

0 comments on commit 167c7a3

Please sign in to comment.