Skip to content

Commit

Permalink
Merge pull request #276 from shubhamcoc/log_race_bugfix
Browse files Browse the repository at this point in the history
fix: added mutex lock and unlock around read to logger struct for con…
  • Loading branch information
vlastahajek authored Sep 16, 2021
2 parents cd0d5b4 + d715542 commit 18cfd3d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,58 @@ func (l *logger) SetPrefix(prefix string) {
}

func (l *logger) Debugf(format string, v ...interface{}) {
l.lock.Lock()
if l.logLevel >= DebugLevel {
log.Print(l.prefix, " D! ", fmt.Sprintf(format, v...))
}
l.lock.Unlock()
}
func (l *logger) Debug(msg string) {
l.lock.Lock()
if l.logLevel >= DebugLevel {
log.Print(l.prefix, " D! ", msg)
}
l.lock.Unlock()
}

func (l *logger) Infof(format string, v ...interface{}) {
l.lock.Lock()
if l.logLevel >= InfoLevel {
log.Print(l.prefix, " I! ", fmt.Sprintf(format, v...))
}
l.lock.Unlock()
}
func (l *logger) Info(msg string) {
l.lock.Lock()
if l.logLevel >= DebugLevel {
log.Print(l.prefix, " I! ", msg)
}
l.lock.Unlock()
}

func (l *logger) Warnf(format string, v ...interface{}) {
l.lock.Lock()
if l.logLevel >= WarningLevel {
log.Print(l.prefix, " W! ", fmt.Sprintf(format, v...))
}
l.lock.Unlock()
}
func (l *logger) Warn(msg string) {
l.lock.Lock()
if l.logLevel >= WarningLevel {
log.Print(l.prefix, " W! ", msg)
}
l.lock.Unlock()
}

func (l *logger) Errorf(format string, v ...interface{}) {
l.lock.Lock()
log.Print(l.prefix, " E! ", fmt.Sprintf(format, v...))
l.lock.Unlock()
}

func (l *logger) Error(msg string) {
l.lock.Lock()
log.Print(l.prefix, " [E]! ", msg)
l.lock.Unlock()
}

0 comments on commit 18cfd3d

Please sign in to comment.