diff --git a/logger.go b/logger.go index e1f024a72..1b59cd5a4 100644 --- a/logger.go +++ b/logger.go @@ -6,6 +6,7 @@ import ( "log" "strconv" "strings" + "sync" ) type StdLogger interface { @@ -32,12 +33,32 @@ func (n nopLogger) Debug(_ string, _ ...LogField) {} type testLogger struct { capture bytes.Buffer + mu sync.Mutex } -func (l *testLogger) Print(v ...interface{}) { fmt.Fprint(&l.capture, v...) } -func (l *testLogger) Printf(format string, v ...interface{}) { fmt.Fprintf(&l.capture, format, v...) } -func (l *testLogger) Println(v ...interface{}) { fmt.Fprintln(&l.capture, v...) } -func (l *testLogger) String() string { return l.capture.String() } +func (l *testLogger) Print(v ...interface{}) { + l.mu.Lock() + defer l.mu.Unlock() + fmt.Fprint(&l.capture, v...) +} + +func (l *testLogger) Printf(format string, v ...interface{}) { + l.mu.Lock() + defer l.mu.Unlock() + fmt.Fprintf(&l.capture, format, v...) +} + +func (l *testLogger) Println(v ...interface{}) { + l.mu.Lock() + defer l.mu.Unlock() + fmt.Fprintln(&l.capture, v...) +} + +func (l *testLogger) String() string { + l.mu.Lock() + defer l.mu.Unlock() + return l.capture.String() +} type defaultLogger struct{}