Skip to content

Commit

Permalink
fix: respect log level settings
Browse files Browse the repository at this point in the history
Signed-off-by: Dong Wang <[email protected]>
  • Loading branch information
wd committed Nov 1, 2024
1 parent a5acd25 commit ff92d95
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 ff92d95

Please sign in to comment.