From 42577840a28f94052b082f954b53139367cf78cc Mon Sep 17 00:00:00 2001 From: lv Date: Tue, 8 Nov 2022 14:29:35 +0800 Subject: [PATCH] [feature]set loglevel as flag Signed-off-by: yanru.lv --- cmd/redisoperator/main.go | 9 +++------ cmd/utils/flags.go | 5 ++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/redisoperator/main.go b/cmd/redisoperator/main.go index 1961dac28..4b170fadf 100644 --- a/cmd/redisoperator/main.go +++ b/cmd/redisoperator/main.go @@ -55,12 +55,9 @@ func (m *Main) Run() error { errC := make(chan error) // Set correct logging. - if m.flags.Debug { - err := m.logger.Set("debug") - if err != nil { - return err - } - m.logger.Debugf("debug mode activated") + err := m.logger.Set(log.Level(strings.ToLower(m.flags.LogLevel))) + if err != nil { + return err } // Create the metrics client. diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2dabd1fda..af2cf78e5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -13,9 +13,9 @@ import ( type CMDFlags struct { KubeConfig string Development bool - Debug bool ListenAddr string MetricsPath string + LogLevel string } // Init initializes and parse the flags @@ -24,10 +24,9 @@ func (c *CMDFlags) Init() { // register flags flag.StringVar(&c.KubeConfig, "kubeconfig", kubehome, "kubernetes configuration path, only used when development mode enabled") flag.BoolVar(&c.Development, "development", false, "development flag will allow to run the operator outside a kubernetes cluster") - flag.BoolVar(&c.Debug, "debug", false, "enable debug mode") flag.StringVar(&c.ListenAddr, "listen-address", ":9710", "Address to listen on for metrics.") flag.StringVar(&c.MetricsPath, "metrics-path", "/metrics", "Path to serve the metrics.") - + flag.StringVar(&c.LogLevel, "log-level", "info", "set log level") // Parse flags flag.Parse() }