Skip to content

Commit

Permalink
Refactor logger.New to accept FieldLogger (#824)
Browse files Browse the repository at this point in the history
* Refactor logger.New to accept FieldLogger

While doing this I've also refactored the code a little bit. Let me know
if you think the otherwise.
  • Loading branch information
inancgumus committed Mar 13, 2023
1 parent 093e98d commit ef2ed4d
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,21 @@ func NewNullLogger() *Logger {
}

// New creates a new logger.
func New(logger *logrus.Logger, iterID string) *Logger {
var defLogger bool
if logger == nil {
defLogger = true
logger = logrus.New()
}
l := &Logger{
Logger: logger,
func New(logger logrus.FieldLogger, iterID string) *Logger {
ll := &Logger{
Logger: logrus.New(),
iterID: iterID,
}
if defLogger {
l.Warnf("Logger", "no logger supplied, using default")

if logger == nil {
ll.Warnf("Logger", "no logger supplied, using default")
} else if l, ok := logger.(*logrus.Logger); !ok {
ll.Warnf("Logger", "invalid logger type %T, using default", logger)
} else {
ll.Logger = l
}

return l
return ll
}

// Tracef logs a trace message.
Expand Down

0 comments on commit ef2ed4d

Please sign in to comment.