@@ -179,7 +179,11 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
179179 "P" ,
180180 viper .GetString ("WATCHTOWER_PORCELAIN" ),
181181 `Write session results to stdout using a stable versioned format. Supported values: "v1"` )
182-
182+
183+ flags .String (
184+ "log-level" ,
185+ viper .GetString ("WATCHTOWER_LOG_LEVEL" ),
186+ "The maximum log level that will be written to STDERR. Possible values: panic, fatal, error, warn, info, debug or trace" )
183187}
184188
185189// RegisterNotificationFlags that are used by watchtower to send notifications
@@ -373,6 +377,7 @@ func SetDefaults() {
373377 viper .SetDefault ("WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT" , 25 )
374378 viper .SetDefault ("WATCHTOWER_NOTIFICATION_EMAIL_SUBJECTTAG" , "" )
375379 viper .SetDefault ("WATCHTOWER_NOTIFICATION_SLACK_IDENTIFIER" , "watchtower" )
380+ viper .SetDefault ("WATCHTOWER_LOG_LEVEL" , "info" )
376381}
377382
378383// EnvConfig translates the command-line options into environment variables
@@ -528,9 +533,9 @@ func ProcessFlagAliases(flags *pflag.FlagSet) {
528533 log .Fatalf (`Failed to get flag: %v` , err )
529534 }
530535 if porcelain != "" {
531- if porcelain != "v1" {
532- log .Fatalf (`Unknown porcelain version %q. Supported values: "v1"` , porcelain )
533- }
536+ if porcelain != "v1" {
537+ log .Fatalf (`Unknown porcelain version %q. Supported values: "v1"` , porcelain )
538+ }
534539 if err = appendFlagValue (flags , `notification-url` , `logger://` ); err != nil {
535540 log .Errorf (`Failed to set flag: %v` , err )
536541 }
@@ -549,6 +554,23 @@ func ProcessFlagAliases(flags *pflag.FlagSet) {
549554 interval , _ := flags .GetInt (`interval` )
550555 flags .Set (`schedule` , fmt .Sprintf (`@every %ds` , interval ))
551556 }
557+
558+ if flagIsEnabled (flags , `debug` ) {
559+ flags .Set (`log-level` , `debug` )
560+ }
561+
562+ if flagIsEnabled (flags , `trace` ) {
563+ flags .Set (`log-level` , `trace` )
564+ }
565+
566+ }
567+
568+ func flagIsEnabled (flags * pflag.FlagSet , name string ) bool {
569+ value , err := flags .GetBool (name )
570+ if err != nil {
571+ log .Fatalf (`The flag %q is not defined` , name )
572+ }
573+ return value
552574}
553575
554576func appendFlagValue (flags * pflag.FlagSet , name string , values ... string ) error {
0 commit comments