Skip to content

Commit 684679d

Browse files
committed
Add log-level support
1 parent be7edd7 commit 684679d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

internal/commands/create.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,20 @@ Create constraints with the Gatekeeper enforcement action set to dryrun
6464
return fmt.Errorf("bind partial-constraints flag: %w", err)
6565
}
6666

67+
if err := viper.BindPFlag("log-level", cmd.PersistentFlags().Lookup("log-level")); err != nil {
68+
return fmt.Errorf("bind log-level flag: %w", err)
69+
}
70+
6771
if cmd.PersistentFlags().Lookup("constraint-template-custom-template-file").Changed && cmd.PersistentFlags().Lookup("constraint-template-version").Changed {
6872
return fmt.Errorf("need to set either constraint-template-custom-template-file or constraint-template-version")
6973
}
70-
74+
if cmd.PersistentFlags().Lookup("log-level").Changed {
75+
level, err := log.ParseLevel(viper.GetString("log-level"))
76+
if err != nil {
77+
return fmt.Errorf("Unknown log level, need to use error, info, debug or trace")
78+
}
79+
log.SetLevel(level)
80+
}
7181
path := "."
7282
if len(args) > 0 {
7383
path = args[0]
@@ -84,7 +94,7 @@ Create constraints with the Gatekeeper enforcement action set to dryrun
8494
cmd.PersistentFlags().Bool("partial-constraints", false, "Generate partial Constraints for policies with parameters")
8595
cmd.PersistentFlags().String("constraint-template-custom-template-file", "", "Path to a custom template file to generate constraint templates")
8696
cmd.PersistentFlags().String("constraint-custom-template-file", "", "Path to a custom template file to generate constraints")
87-
97+
cmd.PersistentFlags().String("log-level", "info", "Set a log level error, info, debug, trace")
8898
return &cmd
8999
}
90100

@@ -100,6 +110,8 @@ func runCreateCommand(path string) error {
100110
"src": violation.Path(),
101111
})
102112

113+
logger.Debug("Rendering policy")
114+
103115
if violation.SkipTemplate() {
104116
logger.Info("Skipping constrainttemplate generation due to configuration")
105117
continue

0 commit comments

Comments
 (0)