From c4c2c4fb141c46fc0d6d7547700bdec4c9046a84 Mon Sep 17 00:00:00 2001 From: Szupingwang Date: Thu, 19 Sep 2024 14:38:06 +0800 Subject: [PATCH] core: minor fix for the log wrapper with debug purpose (#30454) After this PR, https://github.com/ethereum/go-ethereum/pull/28187, the way to set the default logger is different. This PR only updates the way to set logger in some test cases' comments that existed in the codebase (since this commit https://github.com/ethereum/go-ethereum/commit/b63e3c37a6). Although I am not sure if it a good way to leave the code in the comment, it truly makes me more efficiently to debug and fix the failing test cases. --- core/blockchain_repair_test.go | 6 +++--- core/blockchain_sethead_test.go | 2 +- core/blockchain_snapshot_test.go | 20 ++++++++++---------- core/blockchain_test.go | 14 +++++++------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/core/blockchain_repair_test.go b/core/blockchain_repair_test.go index 07f154b4fa..aeeb9095d8 100644 --- a/core/blockchain_repair_test.go +++ b/core/blockchain_repair_test.go @@ -1757,8 +1757,8 @@ func testRepair(t *testing.T, tt *rewindTest, snapshots bool) { func testRepairWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme string) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump(true)) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(tt.dump(false)) // Create a temporary persistent database datadir := t.TempDir() @@ -1908,7 +1908,7 @@ func TestIssue23496(t *testing.T) { func testIssue23496(t *testing.T, scheme string) { // It's hard to follow the test case, visualize the input - //log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) // Create a temporary persistent database datadir := t.TempDir() diff --git a/core/blockchain_sethead_test.go b/core/blockchain_sethead_test.go index 5a62d6b25f..123c2c9af1 100644 --- a/core/blockchain_sethead_test.go +++ b/core/blockchain_sethead_test.go @@ -1961,7 +1961,7 @@ func testSetHead(t *testing.T, tt *rewindTest, snapshots bool) { func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme string) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) // fmt.Println(tt.dump(false)) // Create a temporary persistent database diff --git a/core/blockchain_snapshot_test.go b/core/blockchain_snapshot_test.go index 45d33bb0a0..3803c153e7 100644 --- a/core/blockchain_snapshot_test.go +++ b/core/blockchain_snapshot_test.go @@ -222,8 +222,8 @@ type snapshotTest struct { func (snaptest *snapshotTest) test(t *testing.T) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump()) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(snaptest.dump()) chain, blocks := snaptest.prepare(t) // Restart the chain normally @@ -245,8 +245,8 @@ type crashSnapshotTest struct { func (snaptest *crashSnapshotTest) test(t *testing.T) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump()) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(snaptest.dump()) chain, blocks := snaptest.prepare(t) // Pull the plug on the database, simulating a hard crash @@ -297,8 +297,8 @@ type gappedSnapshotTest struct { func (snaptest *gappedSnapshotTest) test(t *testing.T) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump()) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(snaptest.dump()) chain, blocks := snaptest.prepare(t) // Insert blocks without enabling snapshot if gapping is required. @@ -341,8 +341,8 @@ type setHeadSnapshotTest struct { func (snaptest *setHeadSnapshotTest) test(t *testing.T) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump()) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(snaptest.dump()) chain, blocks := snaptest.prepare(t) // Rewind the chain if setHead operation is required. @@ -370,8 +370,8 @@ type wipeCrashSnapshotTest struct { func (snaptest *wipeCrashSnapshotTest) test(t *testing.T) { // It's hard to follow the test case, visualize the input - // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) - // fmt.Println(tt.dump()) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) + // fmt.Println(snaptest.dump()) chain, blocks := snaptest.prepare(t) // Firstly, stop the chain properly, with all snapshot journal diff --git a/core/blockchain_test.go b/core/blockchain_test.go index d8c436fcd6..d2bf074c65 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -2126,9 +2126,9 @@ func testSideImport(t *testing.T, numCanonBlocksInSidechain, blocksBetweenCommon // [ Cn, Cn+1, Cc, Sn+3 ... Sm] // ^ ^ ^ pruned func TestPrunedImportSide(t *testing.T) { - //glogger := log.NewGlogHandler(log.StreamHandler(os.Stdout, log.TerminalFormat(false))) - //glogger.Verbosity(3) - //log.Root().SetHandler(log.Handler(glogger)) + // glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) + // glogger.Verbosity(3) + // log.SetDefault(log.NewLogger(glogger)) testSideImport(t, 3, 3, -1) testSideImport(t, 3, -3, -1) testSideImport(t, 10, 0, -1) @@ -2137,9 +2137,9 @@ func TestPrunedImportSide(t *testing.T) { } func TestPrunedImportSideWithMerging(t *testing.T) { - //glogger := log.NewGlogHandler(log.StreamHandler(os.Stdout, log.TerminalFormat(false))) - //glogger.Verbosity(3) - //log.Root().SetHandler(log.Handler(glogger)) + // glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) + // glogger.Verbosity(3) + // log.SetDefault(log.NewLogger(glogger)) testSideImport(t, 3, 3, 0) testSideImport(t, 3, -3, 0) testSideImport(t, 10, 0, 0) @@ -3629,7 +3629,7 @@ func TestSetCanonical(t *testing.T) { } func testSetCanonical(t *testing.T, scheme string) { - //log.Root().SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StreamHandler(os.Stderr, log.TerminalFormat(true)))) + // log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(os.Stderr, log.LevelInfo, true))) var ( key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")