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 95bfbde
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,22 @@ 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")
}
l := &Logger{
Logger: logger,
iterID: iterID,
}
if defLogger {
l.Warnf("Logger", "no logger supplied, using default")
var ok bool
if ll, ok = logger.(*logrus.Logger); !ok {
// panic so that we know when to upgrade. see issue #818.
panic("logger is not a logrus.Logger")
}

return l
return &Logger{
Logger: ll,
iterID: iterID,
}
}

// Tracef logs a trace message.
Expand Down

0 comments on commit 95bfbde

Please sign in to comment.