Skip to content

Commit 553bafc

Browse files
authored
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.
1 parent 05bbc56 commit 553bafc

File tree

6 files changed

+5
-29
lines changed

6 files changed

+5
-29
lines changed

cmd/bootnode/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import (
3232
"github.com/ethereum/go-ethereum/p2p/enode"
3333
"github.com/ethereum/go-ethereum/p2p/nat"
3434
"github.com/ethereum/go-ethereum/p2p/netutil"
35-
"golang.org/x/exp/slog"
3635
)
3736

3837
func main() {
@@ -45,7 +44,7 @@ func main() {
4544
natdesc = flag.String("nat", "none", "port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>)")
4645
netrestrict = flag.String("netrestrict", "", "restrict network communication to the given IP networks (CIDR masks)")
4746
runv5 = flag.Bool("v5", false, "run a v5 topic discovery bootnode")
48-
verbosity = flag.Int("verbosity", int(log.LvlInfo), "log verbosity (0-5)")
47+
verbosity = flag.Int("verbosity", 3, "log verbosity (0-5)")
4948
vmodule = flag.String("vmodule", "", "log verbosity pattern")
5049

5150
nodeKey *ecdsa.PrivateKey
@@ -54,7 +53,8 @@ func main() {
5453
flag.Parse()
5554

5655
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
57-
glogger.Verbosity(slog.Level(*verbosity))
56+
slogVerbosity := log.FromLegacyLevel(*verbosity)
57+
glogger.Verbosity(slogVerbosity)
5858
glogger.Vmodule(*vmodule)
5959
log.SetDefault(log.NewLogger(glogger))
6060

cmd/clef/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import (
5757
"github.com/mattn/go-colorable"
5858
"github.com/mattn/go-isatty"
5959
"github.com/urfave/cli/v2"
60-
"golang.org/x/exp/slog"
6160
)
6261

6362
const legalWarning = `
@@ -493,7 +492,8 @@ func initialize(c *cli.Context) error {
493492
if usecolor {
494493
output = colorable.NewColorable(logOutput)
495494
}
496-
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, slog.Level(c.Int(logLevelFlag.Name)), usecolor)))
495+
verbosity := log.FromLegacyLevel(c.Int(logLevelFlag.Name))
496+
log.SetDefault(log.NewLogger(log.NewTerminalHandlerWithLevel(output, verbosity, usecolor)))
497497

498498
return nil
499499
}

cmd/evm/internal/t8ntool/block.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import (
3030
"github.com/ethereum/go-ethereum/consensus/clique"
3131
"github.com/ethereum/go-ethereum/core/types"
3232
"github.com/ethereum/go-ethereum/crypto"
33-
"github.com/ethereum/go-ethereum/log"
3433
"github.com/ethereum/go-ethereum/rlp"
3534
"github.com/urfave/cli/v2"
36-
"golang.org/x/exp/slog"
3735
)
3836

3937
//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) {
216214

217215
// BuildBlock constructs a block from the given inputs.
218216
func BuildBlock(ctx *cli.Context) error {
219-
// Configure the go-ethereum logger
220-
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
221-
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
222-
log.SetDefault(log.NewLogger(glogger))
223-
224217
baseDir, err := createBasedir(ctx)
225218
if err != nil {
226219
return NewError(ErrorIO, fmt.Errorf("failed creating output basedir: %v", err))

cmd/evm/internal/t8ntool/transaction.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@ import (
2828
"github.com/ethereum/go-ethereum/common/hexutil"
2929
"github.com/ethereum/go-ethereum/core"
3030
"github.com/ethereum/go-ethereum/core/types"
31-
"github.com/ethereum/go-ethereum/log"
3231
"github.com/ethereum/go-ethereum/params"
3332
"github.com/ethereum/go-ethereum/rlp"
3433
"github.com/ethereum/go-ethereum/tests"
3534
"github.com/urfave/cli/v2"
36-
"golang.org/x/exp/slog"
3735
)
3836

3937
type result struct {
@@ -66,11 +64,6 @@ func (r *result) MarshalJSON() ([]byte, error) {
6664
}
6765

6866
func Transaction(ctx *cli.Context) error {
69-
// Configure the go-ethereum logger
70-
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
71-
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
72-
log.SetDefault(log.NewLogger(glogger))
73-
7467
var (
7568
err error
7669
)

cmd/evm/internal/t8ntool/transition.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ import (
2424
"os"
2525
"path"
2626

27-
"golang.org/x/exp/slog"
28-
2927
"github.com/ethereum/go-ethereum/common"
3028
"github.com/ethereum/go-ethereum/common/hexutil"
3129
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
@@ -82,11 +80,6 @@ type input struct {
8280
}
8381

8482
func Transition(ctx *cli.Context) error {
85-
// Configure the go-ethereum logger
86-
glogger := log.NewGlogHandler(log.NewTerminalHandler(os.Stderr, false))
87-
glogger.Verbosity(slog.Level(ctx.Int(VerbosityFlag.Name)))
88-
log.SetDefault(log.NewLogger(glogger))
89-
9083
var (
9184
err error
9285
tracer vm.EVMLogger

cmd/evm/main.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ var stateTransitionCommand = &cli.Command{
158158
t8ntool.ForknameFlag,
159159
t8ntool.ChainIDFlag,
160160
t8ntool.RewardFlag,
161-
t8ntool.VerbosityFlag,
162161
},
163162
}
164163

@@ -171,7 +170,6 @@ var transactionCommand = &cli.Command{
171170
t8ntool.InputTxsFlag,
172171
t8ntool.ChainIDFlag,
173172
t8ntool.ForknameFlag,
174-
t8ntool.VerbosityFlag,
175173
},
176174
}
177175

@@ -188,7 +186,6 @@ var blockBuilderCommand = &cli.Command{
188186
t8ntool.InputWithdrawalsFlag,
189187
t8ntool.InputTxsRlpFlag,
190188
t8ntool.SealCliqueFlag,
191-
t8ntool.VerbosityFlag,
192189
},
193190
}
194191

0 commit comments

Comments
 (0)