Fix a race conditions

Two accesses to a loggers were not protected by a logger's mutex
This commit is contained in:
Bruno Carlin 2020-05-17 14:34:56 +02:00
parent 79da88fda7
commit 572fff1be4

View file

@ -28,11 +28,17 @@ func NewLogger(name string) (l *Logger) {
// AddBackend add a new Backend to the logger. All set backends are kept. // AddBackend add a new Backend to the logger. All set backends are kept.
func (l *Logger) AddBackend(b Backend) { func (l *Logger) AddBackend(b Backend) {
l.Lock()
defer l.Unlock()
l.backends = append(l.backends, b) l.backends = append(l.backends, b)
} }
// SetBackend sets the backend list to the logger. Any existing backend will be lost. // SetBackend sets the backend list to the logger. Any existing backend will be lost.
func (l *Logger) SetBackend(b ...Backend) { func (l *Logger) SetBackend(b ...Backend) {
l.Lock()
defer l.Unlock()
l.backends = b l.backends = b
} }