Skip to content

Commit

Permalink
fix: need a concurrent buffer to run the current logging test
Browse files Browse the repository at this point in the history
  • Loading branch information
mgabeler-lee-6rs committed Dec 8, 2023
1 parent 86361e8 commit efa31a5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,19 @@ func TestLoggerWithLevels(t *testing.T) {
assert.Contains(t, buffer.String(), "FTL")
}

type concurrentBuffer struct {
mu sync.Mutex
b bytes.Buffer
}

func (b *concurrentBuffer) Write(p []byte) (n int, err error) {
b.mu.Lock()
defer b.mu.Unlock()
return b.b.Write(p)
}

func TestCustomLoggerIssue68(t *testing.T) {
buffer := new(bytes.Buffer)
buffer := new(concurrentBuffer)
gin.SetMode(gin.ReleaseMode)
r := gin.New()
l := zerolog.New(buffer)
Expand All @@ -179,7 +190,7 @@ func TestCustomLoggerIssue68(t *testing.T) {
}
wg.Wait()

bs := buffer.String()
bs := buffer.b.String()
for i := 0; i < 10; i++ {
// should contain each request log exactly once
msg := fmt.Sprintf("/example?a=%d", i)
Expand Down

0 comments on commit efa31a5

Please sign in to comment.