Skip to content

Commit

Permalink
raft: use mutex in "SetLogger" to avoid race conditions in tests
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <leegyuho@amazon.com>
  • Loading branch information
gyuho committed Jul 29, 2019
1 parent edce266 commit a900ef5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion raft/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"log"
"os"
"sync"
)

type Logger interface {
Expand All @@ -41,11 +42,16 @@ type Logger interface {
Panicf(format string, v ...interface{})
}

func SetLogger(l Logger) { raftLogger = l }
func SetLogger(l Logger) {
raftLoggerMu.Lock()
raftLogger = l
raftLoggerMu.Unlock()
}

var (
defaultLogger = &DefaultLogger{Logger: log.New(os.Stderr, "raft", log.LstdFlags)}
discardLogger = &DefaultLogger{Logger: log.New(ioutil.Discard, "", 0)}
raftLoggerMu sync.Mutex
raftLogger = Logger(defaultLogger)
)

Expand Down

0 comments on commit a900ef5

Please sign in to comment.