Skip to content

Commit

Permalink
Refactor logger.New to accept FieldLogger
Browse files Browse the repository at this point in the history
While doing this I've also cleaned up the code a little bit. Let me know
if you think the otherwise.

Closes: #823
  • Loading branch information
inancgumus committed Mar 10, 2023
1 parent 07526fb commit d70de4a
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@ func NewNullLogger() *Logger {
}

// New creates a new logger.
func New(logger *logrus.Logger, iterID string) *Logger {
var defLogger bool
func New(logger logrus.FieldLogger, iterID string) *Logger {
var ll *logrus.Logger

if logger == nil {
defLogger = true
logger = logrus.New()
ll = logrus.New()
ll.Warn("Logger", "no logger supplied, using default")
} else if l, ok := logger.(*logrus.Logger); ok {
ll = l
} else {
// panic so that we know when to upgrade. see issue #818.
panic("logger is not a logrus.Logger")
}
l := &Logger{
Logger: logger,

return &Logger{
Logger: ll,
iterID: iterID,
}
if defLogger {
l.Warnf("Logger", "no logger supplied, using default")
}

return l
}

// Tracef logs a trace message.
Expand Down

0 comments on commit d70de4a

Please sign in to comment.