Skip to content

Commit

Permalink
Disable logger color code
Browse files Browse the repository at this point in the history
  • Loading branch information
inancgumus committed Nov 23, 2021
1 parent c69d023 commit 02bc305
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions common/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,26 @@ func (l *Logger) Logf(level logrus.Level, category string, msg string, args ...i
if now == elapsed {
elapsed = 0
}
defer func() {
l.lastLogCall = now
}()

if l.categoryFilter == nil || l.categoryFilter.Match([]byte(category)) {
if l.categoryFilter != nil && !l.categoryFilter.Match([]byte(category)) {
return
}
if l.logger == nil {
magenta := color.New(color.FgMagenta).SprintFunc()
if l.logger != nil {
entry := l.logger.WithFields(logrus.Fields{
"category": magenta(category),
"elapsed": fmt.Sprintf("%d ms", elapsed),
"goroutine": goRoutineID(),
})
if l.logger.GetLevel() < level && l.debugOverride {
entry.Printf(msg, args...)
} else {
entry.Logf(level, msg, args...)
}
} else {
fmt.Printf("%s [%d]: %s - %s ms\n", magenta(category), goRoutineID(), string(msg), magenta(elapsed))
}
l.lastLogCall = now
fmt.Printf("%s [%d]: %s - %s ms\n", magenta(category), goRoutineID(), string(msg), magenta(elapsed))
return
}
entry := l.logger.WithFields(logrus.Fields{
"category": category,
"elapsed": fmt.Sprintf("%d ms", elapsed),
"goroutine": goRoutineID(),
})
if l.logger.GetLevel() < level && l.debugOverride {
entry.Printf(msg, args...)
return
}
entry.Logf(level, msg, args...)
}

0 comments on commit 02bc305

Please sign in to comment.