From 45d1052229f5390d76e912f15e17240a0eddc7b9 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 14 Oct 2014 14:35:54 +0200 Subject: [PATCH] ethlog: fix StdLogSystem data race on level --- ethlog/loggers.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ethlog/loggers.go b/ethlog/loggers.go index 34561853a9..edf77bda12 100644 --- a/ethlog/loggers.go +++ b/ethlog/loggers.go @@ -6,6 +6,7 @@ import ( "log" "os" "sync" + "sync/atomic" ) type LogSystem interface { @@ -198,7 +199,7 @@ func (logger *Logger) Fatalf(format string, v ...interface{}) { type StdLogSystem struct { logger *log.Logger - level LogLevel + level uint32 } func (t *StdLogSystem) Println(v ...interface{}) { @@ -210,14 +211,14 @@ func (t *StdLogSystem) Printf(format string, v ...interface{}) { } func (t *StdLogSystem) SetLogLevel(i LogLevel) { - t.level = i + atomic.StoreUint32(&t.level, uint32(i)) } func (t *StdLogSystem) GetLogLevel() LogLevel { - return t.level + return LogLevel(atomic.LoadUint32(&t.level)) } func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) *StdLogSystem { logger := log.New(writer, "", flags) - return &StdLogSystem{logger, level} + return &StdLogSystem{logger, uint32(level)} }