From b61bbbfd0f8d47bbf0f015a1f2474975f288e1d6 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Mon, 13 Nov 2023 20:43:27 +0100 Subject: [PATCH] log, debug: make terminal handler public, change how to reset fieldpadding map --- cmd/abigen/main.go | 2 +- cmd/bootnode/main.go | 2 +- cmd/clef/main.go | 2 +- cmd/evm/internal/t8ntool/block.go | 2 +- cmd/evm/internal/t8ntool/transaction.go | 2 +- cmd/evm/internal/t8ntool/transition.go | 2 +- cmd/faucet/faucet.go | 2 +- cmd/geth/logtestcmd_active.go | 7 ++---- core/state/snapshot/generate_test.go | 2 +- core/txpool/blobpool/blobpool_test.go | 10 ++++---- eth/catalyst/api_test.go | 2 +- internal/debug/flags.go | 24 ++++++++++++------- internal/testlog/testlog.go | 2 +- les/api_test.go | 2 +- log/format.go | 4 ++-- log/handler.go | 31 +++++++++++++++---------- log/logger_test.go | 6 ++--- miner/stress/clique/main.go | 2 +- p2p/simulations/adapters/exec.go | 2 +- p2p/simulations/examples/ping-pong.go | 2 +- p2p/simulations/http_test.go | 2 +- signer/storage/aes_gcm_storage_test.go | 4 ++-- 22 files changed, 64 insertions(+), 52 deletions(-) diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go index cf206bb54b..0149dec527 100644 --- a/cmd/abigen/main.go +++ b/cmd/abigen/main.go @@ -232,7 +232,7 @@ func abigen(c *cli.Context) error { } func main() { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) if err := app.Run(os.Args); err != nil { fmt.Fprintln(os.Stderr, err) diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index 2c7ccf60bc..1660b43b74 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -53,7 +53,7 @@ func main() { ) flag.Parse() - glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false)) + glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) glogger.Verbosity(slog.Level(*verbosity)) glogger.Vmodule(*vmodule) log.SetDefault(log.NewLogger(glogger)) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index b1328a3fd6..b32179a364 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -493,7 +493,7 @@ func initialize(c *cli.Context) error { if usecolor { output = colorable.NewColorable(logOutput) } - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor))) return nil } diff --git a/cmd/evm/internal/t8ntool/block.go b/cmd/evm/internal/t8ntool/block.go index 00e25b596a..4953fe841d 100644 --- a/cmd/evm/internal/t8ntool/block.go +++ b/cmd/evm/internal/t8ntool/block.go @@ -218,7 +218,7 @@ func (i *bbInput) sealClique(block *types.Block) (*types.Block, error) { // BuildBlock constructs a block from the given inputs. func BuildBlock(ctx *cli.Context) error { // Configure the go-ethereum logger - glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false)) + glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) log.SetDefault(log.NewLogger(glogger)) diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index a71af5141d..e1c98c7fe2 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -67,7 +67,7 @@ func (r *result) MarshalJSON() ([]byte, error) { func Transaction(ctx *cli.Context) error { // Configure the go-ethereum logger - glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false)) + glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) log.SetDefault(log.NewLogger(glogger)) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index e109aa5c01..a01dfedab9 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -83,7 +83,7 @@ type input struct { func Transition(ctx *cli.Context) error { // Configure the go-ethereum logger - glogger := log.NewGlogHandler(log.TerminalHandler(os.Stderr, false)) + glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) log.SetDefault(log.NewLogger(glogger)) diff --git a/cmd/faucet/faucet.go b/cmd/faucet/faucet.go index a8d570c61e..e00e04f93e 100644 --- a/cmd/faucet/faucet.go +++ b/cmd/faucet/faucet.go @@ -100,7 +100,7 @@ var websiteTmpl string func main() { // Parse the flags and set up the logger to print everything requested flag.Parse() - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, slog.Level(*logFlag), true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, slog.Level(*logFlag), true))) // Construct the payout tiers amounts := make([]string, *tiersFlag) diff --git a/cmd/geth/logtestcmd_active.go b/cmd/geth/logtestcmd_active.go index 315e9af780..0ca4cc621d 100644 --- a/cmd/geth/logtestcmd_active.go +++ b/cmd/geth/logtestcmd_active.go @@ -23,7 +23,6 @@ import ( "fmt" "math" "math/big" - "os" "time" "github.com/ethereum/go-ethereum/common" @@ -51,10 +50,8 @@ func (c customQuotedStringer) String() string { // logTest is an entry point which spits out some logs. This is used by testing // to verify expected outputs func logTest(ctx *cli.Context) error { - // if log is set to output terminal format, reset root logger to clear field padding map - if !ctx.IsSet(debug.LogFormatFlag.Name) || ctx.String(debug.LogFormatFlag.Name) == "terminal" { - log.SetDefault(log.NewLogger(log.TerminalHandler(os.Stdout, false))) - } + // clear field padding map + debug.ResetLogging() { // big.Int ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999" diff --git a/core/state/snapshot/generate_test.go b/core/state/snapshot/generate_test.go index 4ad9bd8a60..c25f3e7e8b 100644 --- a/core/state/snapshot/generate_test.go +++ b/core/state/snapshot/generate_test.go @@ -601,7 +601,7 @@ func testGenerateWithExtraAccounts(t *testing.T, scheme string) { } func enableLogging() { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) } // Tests that snapshot generation when an extra account with storage exists in the snap state. diff --git a/core/txpool/blobpool/blobpool_test.go b/core/txpool/blobpool/blobpool_test.go index 7eaf93ac19..fa3e8edc90 100644 --- a/core/txpool/blobpool/blobpool_test.go +++ b/core/txpool/blobpool/blobpool_test.go @@ -319,7 +319,7 @@ func verifyPoolInternals(t *testing.T, pool *BlobPool) { // - 3. All transactions after a nonce gap must be dropped // - 4. All transactions after an underpriced one (including it) must be dropped func TestOpenDrops(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) // Create a temporary folder for the persistent backend storage, _ := os.MkdirTemp("", "blobpool-") @@ -600,7 +600,7 @@ func TestOpenDrops(t *testing.T) { // - 2. Eviction thresholds are calculated correctly for the sequences // - 3. Balance usage of an account is totals across all transactions func TestOpenIndex(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) // Create a temporary folder for the persistent backend storage, _ := os.MkdirTemp("", "blobpool-") @@ -689,7 +689,7 @@ func TestOpenIndex(t *testing.T) { // Tests that after indexing all the loaded transactions from disk, a price heap // is correctly constructed based on the head basefee and blobfee. func TestOpenHeap(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) // Create a temporary folder for the persistent backend storage, _ := os.MkdirTemp("", "blobpool-") @@ -776,7 +776,7 @@ func TestOpenHeap(t *testing.T) { // Tests that after the pool's previous state is loaded back, any transactions // over the new storage cap will get dropped. func TestOpenCap(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) // Create a temporary folder for the persistent backend storage, _ := os.MkdirTemp("", "blobpool-") @@ -868,7 +868,7 @@ func TestOpenCap(t *testing.T) { // specific to the blob pool. It does not do an exhaustive transaction validity // check. func TestAdd(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, true))) // seed is a helper tumpe to seed an initial state db and pool type seed struct { diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 7351d0b889..c875c485dd 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -1562,7 +1562,7 @@ func TestBlockToPayloadWithBlobs(t *testing.T) { // This checks that beaconRoot is applied to the state from the engine API. func TestParentBeaconBlockRoot(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), log.LevelTrace, true))) genesis, blocks := generateMergeChain(10, true) diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 45eb4af679..c5ad975258 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -66,7 +66,7 @@ var ( Hidden: true, Category: flags.LoggingCategory, } - LogFormatFlag = &cli.StringFlag{ + logFormatFlag = &cli.StringFlag{ Name: "log.format", Usage: "Log format to use (json|logfmt|terminal)", Category: flags.LoggingCategory, @@ -151,7 +151,7 @@ var Flags = []cli.Flag{ logVmoduleFlag, vmoduleFlag, logjsonFlag, - LogFormatFlag, + logFormatFlag, logFileFlag, logRotateFlag, logMaxSizeMBsFlag, @@ -168,16 +168,24 @@ var Flags = []cli.Flag{ } var ( - glogger *log.GlogHandler - logOutputF *os.File + glogger *log.GlogHandler + logOutputF *os.File + defaultTerminalHandler *log.TerminalHandler ) func init() { - glogger = log.NewGlogHandler(log.TerminalHandler(os.Stderr, false)) + defaultTerminalHandler = log.NewTerminalHandler(os.Stderr, false) + glogger = log.NewGlogHandler(defaultTerminalHandler) glogger.Verbosity(log.LvlInfo) log.SetDefault(log.NewLogger(glogger)) } +func ResetLogging() { + if defaultTerminalHandler != nil { + defaultTerminalHandler.ResetFieldPadding() + } +} + // Setup initializes profiling and logging based on the CLI flags. // It should be called as early as possible in the program. func Setup(ctx *cli.Context) error { @@ -186,7 +194,7 @@ func Setup(ctx *cli.Context) error { fileOutput io.Writer terminalOutput = io.Writer(os.Stderr) output io.Writer - logFmtFlag = ctx.String(LogFormatFlag.Name) + logFmtFlag = ctx.String(logFormatFlag.Name) ) var ( logFile = ctx.String(logFileFlag.Name) @@ -249,10 +257,10 @@ func Setup(ctx *cli.Context) error { output = terminalOutput } } - handler = log.TerminalHandler(output, useColor) + handler = log.NewTerminalHandler(output, useColor) default: // Unknown log format specified - return fmt.Errorf("unknown log format: %v", ctx.String(LogFormatFlag.Name)) + return fmt.Errorf("unknown log format: %v", ctx.String(logFormatFlag.Name)) } glogger = log.NewGlogHandler(handler) diff --git a/internal/testlog/testlog.go b/internal/testlog/testlog.go index f4ab688f8c..3d10a2566c 100644 --- a/internal/testlog/testlog.go +++ b/internal/testlog/testlog.go @@ -166,7 +166,7 @@ func (l *logger) New(ctx ...interface{}) log.Logger { return l.With(ctx...) } -// terminalFormat formats a message similarly to the TerminalHandler in the log package. +// terminalFormat formats a message similarly to the NewTerminalHandler in the log package. // The difference is that terminalFormat does not escape messages/attributes and does not pad attributes. func (h *bufHandler) terminalFormat(r slog.Record) string { buf := &bytes.Buffer{} diff --git a/les/api_test.go b/les/api_test.go index 34daa144e4..5af74e2714 100644 --- a/les/api_test.go +++ b/les/api_test.go @@ -53,7 +53,7 @@ var ( func TestMain(m *testing.M) { flag.Parse() - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true))) // register the Delivery service which will run as a devp2p // protocol when using the exec adapter adapters.RegisterLifecycles(services) diff --git a/log/format.go b/log/format.go index 9266dceb63..e156e4356e 100644 --- a/log/format.go +++ b/log/format.go @@ -44,7 +44,7 @@ type TerminalStringer interface { TerminalString() string } -func (h *terminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte { +func (h *TerminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte { msg := escapeMessage(r.Message) var color = 0 if usecolor { @@ -82,7 +82,7 @@ func (h *terminalHandler) TerminalFormat(r slog.Record, usecolor bool) []byte { return b.Bytes() } -func (h *terminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) { +func (h *TerminalHandler) logfmt(buf *bytes.Buffer, r slog.Record, color int) { attrs := []slog.Attr{} r.Attrs(func(attr slog.Attr) bool { attrs = append(attrs, attr) diff --git a/log/handler.go b/log/handler.go index 773c1058f0..d91d0327d3 100644 --- a/log/handler.go +++ b/log/handler.go @@ -72,7 +72,7 @@ func (h *discardHandler) WithAttrs(attrs []slog.Attr) slog.Handler { return &discardHandler{} } -type terminalHandler struct { +type TerminalHandler struct { mu sync.Mutex wr io.Writer lvl slog.Level @@ -83,7 +83,7 @@ type terminalHandler struct { fieldPadding map[string]int } -// TerminalHandler returns a handler which formats log records at all levels optimized for human readability on +// NewTerminalHandler returns a handler which formats log records at all levels optimized for human readability on // a terminal with color-coded level output and terser human friendly timestamp. // This format should only be used for interactive programs or while developing. // @@ -92,14 +92,14 @@ type terminalHandler struct { // Example: // // [DBUG] [May 16 20:58:45] remove route ns=haproxy addr=127.0.0.1:50002 -func TerminalHandler(wr io.Writer, useColor bool) slog.Handler { - return TerminalHandlerWithLevel(wr, levelMaxVerbosity, useColor) +func NewTerminalHandler(wr io.Writer, useColor bool) *TerminalHandler { + return NewTerminalHandlerWithLevel(wr, levelMaxVerbosity, useColor) } -// TerminalHandlerWithLevel returns the same handler as TerminalHandler but only outputs +// NewTerminalHandlerWithLevel returns the same handler as NewTerminalHandler but only outputs // records which are less than or equal to the specified verbosity level. -func TerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) slog.Handler { - return &terminalHandler{ +func NewTerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) *TerminalHandler { + return &TerminalHandler{ sync.Mutex{}, wr, lvl, @@ -109,23 +109,23 @@ func TerminalHandlerWithLevel(wr io.Writer, lvl slog.Level, useColor bool) slog. } } -func (h *terminalHandler) Handle(_ context.Context, r slog.Record) error { +func (h *TerminalHandler) Handle(_ context.Context, r slog.Record) error { h.mu.Lock() defer h.mu.Unlock() h.wr.Write(h.TerminalFormat(r, h.useColor)) return nil } -func (h *terminalHandler) Enabled(_ context.Context, level slog.Level) bool { +func (h *TerminalHandler) Enabled(_ context.Context, level slog.Level) bool { return level >= h.lvl } -func (h *terminalHandler) WithGroup(name string) slog.Handler { +func (h *TerminalHandler) WithGroup(name string) slog.Handler { panic("not implemented") } -func (h *terminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler { - return &terminalHandler{ +func (h *TerminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler { + return &TerminalHandler{ sync.Mutex{}, h.wr, h.lvl, @@ -135,6 +135,13 @@ func (h *terminalHandler) WithAttrs(attrs []slog.Attr) slog.Handler { } } +// ResetFieldPadding zeroes the field-padding for all attribute pairs. +func (t *TerminalHandler) ResetFieldPadding() { + t.mu.Lock() + t.fieldPadding = make(map[string]int) + t.mu.Unlock() +} + type leveler struct{ minLevel slog.Level } func (l *leveler) Level() slog.Level { diff --git a/log/logger_test.go b/log/logger_test.go index bdf4a51eb4..6bdfa16ccd 100644 --- a/log/logger_test.go +++ b/log/logger_test.go @@ -12,7 +12,7 @@ import ( // TestLoggingWithVmodule checks that vmodule works. func TestLoggingWithVmodule(t *testing.T) { out := new(bytes.Buffer) - glog := NewGlogHandler(TerminalHandlerWithLevel(out, LevelTrace, false)) + glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false)) glog.Verbosity(LevelCrit) logger := NewLogger(glog) logger.Warn("This should not be seen", "ignored", "true") @@ -30,7 +30,7 @@ func TestLoggingWithVmodule(t *testing.T) { func TestTerminalHandlerWithAttrs(t *testing.T) { out := new(bytes.Buffer) - glog := NewGlogHandler(TerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")})) + glog := NewGlogHandler(NewTerminalHandlerWithLevel(out, LevelTrace, false).WithAttrs([]slog.Attr{slog.String("baz", "bat")})) glog.Verbosity(LevelTrace) logger := NewLogger(glog) logger.Trace("a message", "foo", "bar") @@ -45,7 +45,7 @@ func TestTerminalHandlerWithAttrs(t *testing.T) { } func BenchmarkTraceLogging(b *testing.B) { - SetDefault(NewLogger(TerminalHandler(os.Stderr, true))) + SetDefault(NewLogger(NewTerminalHandler(os.Stderr, true))) b.ResetTimer() for i := 0; i < b.N; i++ { Trace("a message", "v", i) diff --git a/miner/stress/clique/main.go b/miner/stress/clique/main.go index a0d0ab4eb4..13336cd83c 100644 --- a/miner/stress/clique/main.go +++ b/miner/stress/clique/main.go @@ -45,7 +45,7 @@ import ( ) func main() { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) fdlimit.Raise(2048) // Generate a batch of accounts to seal and fund with diff --git a/p2p/simulations/adapters/exec.go b/p2p/simulations/adapters/exec.go index 45296f4707..63cc4936c1 100644 --- a/p2p/simulations/adapters/exec.go +++ b/p2p/simulations/adapters/exec.go @@ -403,7 +403,7 @@ func initLogging() { verbosity = log.FromLegacyLevel(int(conf.Node.LogVerbosity)) } // Reinitialize the logger - innerHandler = log.TerminalHandler(writer, true) + innerHandler = log.NewTerminalHandler(writer, true) glogger = log.NewGlogHandler(innerHandler) glogger.Verbosity(verbosity) log.SetDefault(log.NewLogger(glogger)) diff --git a/p2p/simulations/examples/ping-pong.go b/p2p/simulations/examples/ping-pong.go index 11f2bf221c..70b35ad777 100644 --- a/p2p/simulations/examples/ping-pong.go +++ b/p2p/simulations/examples/ping-pong.go @@ -41,7 +41,7 @@ func main() { flag.Parse() // set the log level to Trace - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(os.Stderr, log.LevelTrace, false))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelTrace, false))) // register a single ping-pong service services := map[string]adapters.LifecycleConstructor{ diff --git a/p2p/simulations/http_test.go b/p2p/simulations/http_test.go index 8105afa89d..c53a49797b 100644 --- a/p2p/simulations/http_test.go +++ b/p2p/simulations/http_test.go @@ -44,7 +44,7 @@ func TestMain(m *testing.M) { loglevel := flag.Int("loglevel", 2, "verbosity of logs") flag.Parse() - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.Level(*loglevel), true))) os.Exit(m.Run()) } diff --git a/signer/storage/aes_gcm_storage_test.go b/signer/storage/aes_gcm_storage_test.go index eb32a0a2a8..ed11184440 100644 --- a/signer/storage/aes_gcm_storage_test.go +++ b/signer/storage/aes_gcm_storage_test.go @@ -90,7 +90,7 @@ func TestFileStorage(t *testing.T) { } } func TestEnd2End(t *testing.T) { - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true))) d := t.TempDir() @@ -112,7 +112,7 @@ func TestEnd2End(t *testing.T) { func TestSwappedKeys(t *testing.T) { // It should not be possible to swap the keys/values, so that // K1:V1, K2:V2 can be swapped into K1:V2, K2:V1 - log.SetDefault(log.NewLogger(log.TerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true))) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(colorable.NewColorableStderr(), slog.LevelInfo, true))) d := t.TempDir()