Fix concurrent map write in logger.go
@@ -28,6 +28,7 @@ import (
"path/filepath"
"runtime"
"strconv"
+ "sync"
"time"
"github.com/go-kit/kit/log"
@@ -35,6 +36,8 @@ import (
k8sruntime "k8s.io/apimachinery/pkg/runtime"
)
+var lock sync.Mutex
+
type logLevel int
const (
@@ -99,13 +102,23 @@ var loggers = make(map[string]*FilteredLogger)
var defaultComponent = ""
var defaultVerbosity = 0
-func Logger(component string) *FilteredLogger {
- if _, ok := loggers[component]; !ok {
+func createLogger(component string) {
+ lock.Lock()
+ defer lock.Unlock()
+ _, ok := loggers[component]
+ if ok == false {
logger := log.NewLogfmtLogger(os.Stderr)
log := MakeLogger(logger)
log.component = component
loggers[component] = log
}
+}
+
+func Logger(component string) *FilteredLogger {
+ _, ok := loggers[component]
+ if ok == false {
+ createLogger(component)
+ }
return loggers[component]
}
