Skip to content

Commit

Permalink
[feature]set loglevel as flag
Browse files Browse the repository at this point in the history
Signed-off-by: yanru.lv <[email protected]>
  • Loading branch information
lvyanru8200 committed Nov 8, 2022
1 parent e93a030 commit 4257784
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
9 changes: 3 additions & 6 deletions cmd/redisoperator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand Down

0 comments on commit 4257784

Please sign in to comment.