From 553bafc12720d2a3eef396cfea20f0637fb41cc4 Mon Sep 17 00:00:00 2001 From: Martin HS Date: Mon, 18 Dec 2023 14:11:27 +0100 Subject: [PATCH] cmd/evm, cmd/clef, cmd/bootnode: fix / unify logging (#28696) This change fixes a problem with our non-core binaries: evm, clef, bootnode. First of all, they failed to convert from legacy loglevels 1 to 5, to the new slog loglevels -4 to 4. Secondly, the logging was actually setup in the init phase, and then overridden in the main. This is not needed for evm, since it used the same flag name as the main geth verbosity. Better to let the flags/internal handle the logging init. --- cmd/bootnode/main.go | 6 +++--- cmd/clef/main.go | 4 ++-- cmd/evm/internal/t8ntool/block.go | 7 ------- cmd/evm/internal/t8ntool/transaction.go | 7 ------- cmd/evm/internal/t8ntool/transition.go | 7 ------- cmd/evm/main.go | 3 --- 6 files changed, 5 insertions(+), 29 deletions(-) diff --git a/cmd/bootnode/main.go b/cmd/bootnode/main.go index 1660b43b7..350b85df1 100644 --- a/cmd/bootnode/main.go +++ b/cmd/bootnode/main.go @@ -32,7 +32,6 @@ import ( "github.com/ethereum/go-ethereum/p2p/enode" "github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/p2p/netutil" - "golang.org/x/exp/slog" ) func main() { @@ -45,7 +44,7 @@ func main() { natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|pmp:|extip:)") netrestrict = flag.String("netrestrict", "", "restrict network communication to the given IP networks (CIDR masks)") runv5 = flag.Bool("v5", false, "run a v5 topic discovery bootnode") - verbosity = flag.Int("verbosity", int(log.LvlInfo), "log verbosity (0-5)") + verbosity = flag.Int("verbosity", 3, "log verbosity (0-5)") vmodule = flag.String("vmodule", "", "log verbosity pattern") nodeKey *ecdsa.PrivateKey @@ -54,7 +53,8 @@ func main() { flag.Parse() glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) - glogger.Verbosity(slog.Level(*verbosity)) + slogVerbosity := log.FromLegacyLevel(*verbosity) + glogger.Verbosity(slogVerbosity) glogger.Vmodule(*vmodule) log.SetDefault(log.NewLogger(glogger)) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 27b7b7077..234699136 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -57,7 +57,6 @@ import ( "github.com/mattn/go-colorable" "github.com/mattn/go-isatty" "github.com/urfave/cli/v2" - "golang.org/x/exp/slog" ) const legalWarning = ` @@ -493,7 +492,8 @@ func initialize(c *cli.Context) error { if usecolor { output = colorable.NewColorable(logOutput) } - log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor))) + verbosity := log.FromLegacyLevel(c.Int(logLevelFlag.Name)) + log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, verbosity, usecolor))) return nil } diff --git a/cmd/evm/internal/t8ntool/block.go b/cmd/evm/internal/t8ntool/block.go index 429ae12c5..a2dc47343 100644 --- a/cmd/evm/internal/t8ntool/block.go +++ b/cmd/evm/internal/t8ntool/block.go @@ -30,10 +30,8 @@ import ( "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/rlp" "github.com/urfave/cli/v2" - "golang.org/x/exp/slog" ) //go:generate go run github.com/fjl/gencodec -type header -field-override headerMarshaling -out gen_header.go @@ -216,11 +214,6 @@ 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.NewTerminalHandler(os.Stderr, false)) - glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) - log.SetDefault(log.NewLogger(glogger)) - baseDir, err := createBasedir(ctx) if err != nil { return NewError(ErrorIO, fmt.Errorf("failed creating output basedir: %v", err)) diff --git a/cmd/evm/internal/t8ntool/transaction.go b/cmd/evm/internal/t8ntool/transaction.go index e1c98c7fe..8533b7863 100644 --- a/cmd/evm/internal/t8ntool/transaction.go +++ b/cmd/evm/internal/t8ntool/transaction.go @@ -28,12 +28,10 @@ import ( "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/tests" "github.com/urfave/cli/v2" - "golang.org/x/exp/slog" ) type result struct { @@ -66,11 +64,6 @@ func (r *result) MarshalJSON() ([]byte, error) { } func Transaction(ctx *cli.Context) error { - // Configure the go-ethereum logger - glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) - glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) - log.SetDefault(log.NewLogger(glogger)) - var ( err error ) diff --git a/cmd/evm/internal/t8ntool/transition.go b/cmd/evm/internal/t8ntool/transition.go index a01dfedab..0a9c555cf 100644 --- a/cmd/evm/internal/t8ntool/transition.go +++ b/cmd/evm/internal/t8ntool/transition.go @@ -24,8 +24,6 @@ import ( "os" "path" - "golang.org/x/exp/slog" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/consensus/misc/eip1559" @@ -82,11 +80,6 @@ type input struct { } func Transition(ctx *cli.Context) error { - // Configure the go-ethereum logger - glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false)) - glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name))) - log.SetDefault(log.NewLogger(glogger)) - var ( err error tracer vm.EVMLogger diff --git a/cmd/evm/main.go b/cmd/evm/main.go index ef5d25418..f48685680 100644 --- a/cmd/evm/main.go +++ b/cmd/evm/main.go @@ -158,7 +158,6 @@ var stateTransitionCommand = &cli.Command{ t8ntool.ForknameFlag, t8ntool.ChainIDFlag, t8ntool.RewardFlag, - t8ntool.VerbosityFlag, }, } @@ -171,7 +170,6 @@ var transactionCommand = &cli.Command{ t8ntool.InputTxsFlag, t8ntool.ChainIDFlag, t8ntool.ForknameFlag, - t8ntool.VerbosityFlag, }, } @@ -188,7 +186,6 @@ var blockBuilderCommand = &cli.Command{ t8ntool.InputWithdrawalsFlag, t8ntool.InputTxsRlpFlag, t8ntool.SealCliqueFlag, - t8ntool.VerbosityFlag, }, }