mirror of
https://github.com/golang/go
synced 2024-11-26 18:16:48 -07:00
log/slog: restore the original log setting before test exits
Change-Id: Ib3daffb8a4cc018d62ed6e5741355b1c1a206034 Reviewed-on: https://go-review.googlesource.com/c/go/+/515775 Run-TryBot: Andy Pan <panjf2000@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
parent
0c2abb3233
commit
4e728e5121
@ -12,7 +12,6 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
loginternal "log/internal"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@ -73,9 +72,13 @@ func TestConnections(t *testing.T) {
|
||||
// tests might change the default logger using SetDefault. Also ensure we
|
||||
// restore the default logger at the end of the test.
|
||||
currentLogger := Default()
|
||||
currentLogWriter := log.Writer()
|
||||
currentLogFlags := log.Flags()
|
||||
SetDefault(New(newDefaultHandler(loginternal.DefaultOutput)))
|
||||
t.Cleanup(func() {
|
||||
SetDefault(currentLogger)
|
||||
log.SetOutput(currentLogWriter)
|
||||
log.SetFlags(currentLogFlags)
|
||||
})
|
||||
|
||||
// The default slog.Logger's handler uses the log package's default output.
|
||||
@ -598,10 +601,12 @@ func TestPanics(t *testing.T) {
|
||||
// tests might change the default logger using SetDefault. Also ensure we
|
||||
// restore the default logger at the end of the test.
|
||||
currentLogger := Default()
|
||||
currentLogWriter := log.Writer()
|
||||
currentLogFlags := log.Flags()
|
||||
t.Cleanup(func() {
|
||||
SetDefault(currentLogger)
|
||||
log.SetOutput(os.Stderr)
|
||||
log.SetFlags(log.LstdFlags)
|
||||
log.SetOutput(currentLogWriter)
|
||||
log.SetFlags(currentLogFlags)
|
||||
})
|
||||
|
||||
var logBuf bytes.Buffer
|
||||
|
Loading…
Reference in New Issue
Block a user