Skip to content

Commit

Permalink
Urgent logging fix for gossip
Browse files Browse the repository at this point in the history
This is an urgent logging fix to a bug that might break gossip tests.
in op/go-logging/backend.go,
the log invokes IsEnabledFor which goes to a global field defaultBackend
that IsEnabledFor method for that global field invokes GetLevel
which reads from a map.

If a logger is initalized at the same time another goroutine reads from the map,
a concurrent read-write would occur and will result in panic.

Change-Id: Ief788f3da722aa38b7c743179d6dd1a1dc60936a
Signed-off-by: Yacov Manevich <yacovm@il.ibm.com>
  • Loading branch information
yacovm committed Sep 27, 2016
1 parent 36bc7e7 commit 9617a6e
Showing 1 changed file with 33 additions and 34 deletions.
67 changes: 33 additions & 34 deletions gossip/util/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func init() {
}

type Logger struct {
lock *sync.Mutex
logger logging.Logger
module string
}
Expand Down Expand Up @@ -79,7 +78,7 @@ func GetLogger(module string, peerId string) *Logger {
return nil
}
logging.SetLevel(lvl, module)
lgr := &Logger{lock: &sync.Mutex{}}
lgr := &Logger{}
lgr.logger = *logging.MustGetLogger(module)
lgr.logger.ExtraCalldepth++
lgr.module = module
Expand All @@ -88,97 +87,97 @@ func GetLogger(module string, peerId string) *Logger {
}

func (l *Logger) Fatal(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Fatal(args)
}

func (l *Logger) Fatalf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Fatalf(format, args)
}

func (l *Logger) Panic(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Panic(args)
}

func (l *Logger) Panicf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Panicf(format, args)
}

func (l *Logger) Critical(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Critical(args)
}

func (l *Logger) Criticalf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Criticalf(format, args)
}

func (l *Logger) Error(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Error(args)
}

func (l *Logger) Errorf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Errorf(format, args)
}

func (l *Logger) Warning(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Warning(args)
}

func (l *Logger) Warningf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Warningf(format, args)
}

func (l *Logger) Notice(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Notice(args)
}

func (l *Logger) Noticef(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Noticef(format, args)
}

func (l *Logger) Info(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Info(args)
}

func (l *Logger) Infof(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Infof(format, args)
}

func (l *Logger) Debug(args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Debug(args)
}

func (l *Logger) Debugf(format string, args ...interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
lock.Lock()
defer lock.Unlock()
l.logger.Debugf(format, args)
}

0 comments on commit 9617a6e

Please sign in to comment.