Skip to content

Commit 6f798c0

Browse files
authoredApr 24, 2024··
Merge pull request #638 from diannaowa/loglevel
feat: supports --log-level argument in command line
2 parents de50a0e + 2094906 commit 6f798c0

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed
 

‎internal/pkg/cmd/reloader.go

+13-5
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313

1414
"github.com/sirupsen/logrus"
1515
"github.com/spf13/cobra"
16+
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17+
"k8s.io/apimachinery/pkg/labels"
18+
1619
"github.com/stakater/Reloader/internal/pkg/controller"
1720
"github.com/stakater/Reloader/internal/pkg/metrics"
1821
"github.com/stakater/Reloader/internal/pkg/options"
1922
"github.com/stakater/Reloader/internal/pkg/util"
2023
"github.com/stakater/Reloader/pkg/kube"
21-
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22-
"k8s.io/apimachinery/pkg/labels"
2324
)
2425

2526
// NewReloaderCommand starts the reloader controller
@@ -40,7 +41,8 @@ func NewReloaderCommand() *cobra.Command {
4041
cmd.PersistentFlags().StringVar(&options.SecretReloaderAutoAnnotation, "secret-auto-annotation", "secret.reloader.stakater.com/auto", "annotation to detect changes in secrets")
4142
cmd.PersistentFlags().StringVar(&options.AutoSearchAnnotation, "auto-search-annotation", "reloader.stakater.com/search", "annotation to detect changes in configmaps or secrets tagged with special match annotation")
4243
cmd.PersistentFlags().StringVar(&options.SearchMatchAnnotation, "search-match-annotation", "reloader.stakater.com/match", "annotation to mark secrets or configmaps to match the search")
43-
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON")
44+
cmd.PersistentFlags().StringVar(&options.LogFormat, "log-format", "", "Log format to use (empty string for text, or JSON)")
45+
cmd.PersistentFlags().StringVar(&options.LogLevel, "log-level", "info", "Log level to use (trace, debug, info, warning, error, fatal and panic)")
4446
cmd.PersistentFlags().StringVar(&options.WebhookUrl, "webhook-url", "", "webhook to trigger instead of performing a reload")
4547
cmd.PersistentFlags().StringSlice("resources-to-ignore", []string{}, "list of resources to ignore (valid options 'configMaps' or 'secrets')")
4648
cmd.PersistentFlags().StringSlice("namespaces-to-ignore", []string{}, "list of namespaces to ignore")
@@ -80,7 +82,7 @@ func validateFlags(*cobra.Command, []string) error {
8082
return nil
8183
}
8284

83-
func configureLogging(logFormat string) error {
85+
func configureLogging(logFormat, logLevel string) error {
8486
switch logFormat {
8587
case "json":
8688
logrus.SetFormatter(&logrus.JSONFormatter{})
@@ -90,6 +92,12 @@ func configureLogging(logFormat string) error {
9092
return fmt.Errorf("unsupported logging formatter: %q", logFormat)
9193
}
9294
}
95+
// set log level
96+
level, err := logrus.ParseLevel(logLevel)
97+
if err != nil {
98+
return err
99+
}
100+
logrus.SetLevel(level)
93101
return nil
94102
}
95103

@@ -113,7 +121,7 @@ func getHAEnvs() (string, string) {
113121
}
114122

115123
func startReloader(cmd *cobra.Command, args []string) {
116-
err := configureLogging(options.LogFormat)
124+
err := configureLogging(options.LogFormat, options.LogLevel)
117125
if err != nil {
118126
logrus.Warn(err)
119127
}

‎internal/pkg/options/flags.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ var (
2525
SearchMatchAnnotation = "reloader.stakater.com/match"
2626
// LogFormat is the log format to use (json, or empty string for default)
2727
LogFormat = ""
28+
// LogLevel is the log level to use (trace, debug, info, warning, error, fatal and panic)
29+
LogLevel = ""
2830
// IsArgoRollouts Adds support for argo rollouts
2931
IsArgoRollouts = "false"
3032
// ReloadStrategy Specify the update strategy

0 commit comments

Comments
 (0)
Please sign in to comment.