Skip to content

Commit

Permalink
test: Reset logging to global defaults on cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
fancycode committed May 14, 2024
1 parent 4603b2b commit 94a8f0f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@
package signaling

import (
"io"
"log"
"testing"
)

var (
prevWriter io.Writer
prevFlags int
)

func init() {
prevWriter = log.Writer()
prevFlags = log.Flags()
}

type testLogWriter struct {
t testing.TB
}
Expand All @@ -37,8 +48,6 @@ func (w *testLogWriter) Write(b []byte) (int, error) {
}

func CatchLogForTest(t testing.TB) {
prevWriter := log.Writer()
prevFlags := log.Flags()
t.Cleanup(func() {
log.SetOutput(prevWriter)
log.SetFlags(prevFlags)
Expand Down

0 comments on commit 94a8f0f

Please sign in to comment.