From 572fff1be422bcfed932f47dbdae403a56274060 Mon Sep 17 00:00:00 2001 From: Bruno Carlin Date: Sun, 17 May 2020 14:34:56 +0200 Subject: [PATCH] Fix a race conditions Two accesses to a loggers were not protected by a logger's mutex --- logger.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/logger.go b/logger.go index 4393d49..0f24b48 100644 --- a/logger.go +++ b/logger.go @@ -28,11 +28,17 @@ func NewLogger(name string) (l *Logger) { // AddBackend add a new Backend to the logger. All set backends are kept. func (l *Logger) AddBackend(b Backend) { + l.Lock() + defer l.Unlock() + l.backends = append(l.backends, b) } // SetBackend sets the backend list to the logger. Any existing backend will be lost. func (l *Logger) SetBackend(b ...Backend) { + l.Lock() + defer l.Unlock() + l.backends = b }