Skip to content

Commit

Permalink
fix: respect log level settings (#904)
Browse files Browse the repository at this point in the history
Signed-off-by: Dong Wang <[email protected]>
  • Loading branch information
wd authored Nov 1, 2024
1 parent e09b17d commit 78e925b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,23 @@ func NewContext() *LogContext {

// SetLogLevel sets the log level to use for the logger
func SetLogLevel(logLevel string) error {
var level logrus.Level
switch strings.ToLower(logLevel) {
case "trace":
logger.SetLevel(logrus.TraceLevel)
level = logrus.TraceLevel
case "debug":
logger.SetLevel(logrus.DebugLevel)
level = logrus.DebugLevel
case "info":
logger.SetLevel(logrus.InfoLevel)
level = logrus.InfoLevel
case "warn":
logger.SetLevel(logrus.WarnLevel)
level = logrus.WarnLevel
case "error":
logger.SetLevel(logrus.ErrorLevel)
level = logrus.ErrorLevel
default:
return fmt.Errorf("invalid loglevel: %s", logLevel)
}
logger.SetLevel(level)
logrus.SetLevel(level) // set loglevel for the default logrus.logger
return nil
}

Expand Down

0 comments on commit 78e925b

Please sign in to comment.