Skip to content

Commit

Permalink
Merge pull request #442 from MUzairS15/MUzairS15/logger
Browse files Browse the repository at this point in the history
add support to set loglevel
  • Loading branch information
Mohd Uzair authored Jan 2, 2024
2 parents b998ab4 + f05f3d5 commit 9b066f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 11 additions & 4 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Handler interface {
Debug(description ...interface{})
Warn(err error)
Error(err error)
SetLevel(level logrus.Level)
GetLevel() logrus.Level

// Kubernetes Controller compliant logger
ControllerLogger() logr.Logger
Expand Down Expand Up @@ -57,10 +59,7 @@ func New(appname string, opts Options) (Handler, error) {
log.SetOutput(opts.Output)
}

log.SetLevel(logrus.InfoLevel)
if opts.DebugLevel {
log.SetLevel(logrus.DebugLevel)
}
log.SetLevel(logrus.Level(opts.LogLevel))

entry := log.WithFields(logrus.Fields{"app": appname})
return &Logger{handler: entry}, nil
Expand Down Expand Up @@ -105,3 +104,11 @@ func (l *Logger) Warn(err error) {
"suggested-remediation": errors.GetRemedy(err),
}).Log(logrus.WarnLevel, err.Error())
}

func (l *Logger) SetLevel(level logrus.Level) {
l.handler.Logger.SetLevel(level)
}

func (l *Logger) GetLevel() logrus.Level {
return l.handler.Logger.GetLevel()
}
10 changes: 6 additions & 4 deletions logger/types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package logger

import "io"
import (
"io"
)

const (
JsonLogFormat = iota
Expand All @@ -11,7 +13,7 @@ const (
type Format int

type Options struct {
Format Format
DebugLevel bool
Output io.Writer
Format Format
LogLevel int
Output io.Writer
}

0 comments on commit 9b066f8

Please sign in to comment.