Skip to content

Commit

Permalink
Synchronize LoggerMock (#3)
Browse files Browse the repository at this point in the history
vearutop authored Nov 29, 2020
1 parent 2c708e2 commit d4e057a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mock.go
Original file line number Diff line number Diff line change
@@ -4,10 +4,12 @@ import (
"bytes"
"context"
"encoding/json"
"sync"
)

// LoggerMock logs messages to internal buffer.
type LoggerMock struct {
mu sync.Mutex
bytes.Buffer
OnError func(err error)
}
@@ -29,6 +31,9 @@ func (m *LoggerMock) failed(err error) bool {
}

func (m *LoggerMock) log(ctx context.Context, level, msg string, keysAndValues []interface{}) {
m.mu.Lock()
defer m.mu.Unlock()

jm, err := json.Marshal(Tuples(append(Fields(ctx), keysAndValues...)).Fields())
if m.failed(err) {
return

0 comments on commit d4e057a

Please sign in to comment.