diff --git a/cmd/geth/logtestcmd_active.go b/cmd/geth/logtestcmd_active.go index 4addec0ac7..315e9af780 100644 --- a/cmd/geth/logtestcmd_active.go +++ b/cmd/geth/logtestcmd_active.go @@ -23,9 +23,11 @@ import ( "fmt" "math" "math/big" + "os" "time" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/log" "github.com/holiman/uint256" "github.com/urfave/cli/v2" @@ -49,6 +51,11 @@ 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))) + } + { // big.Int ba, _ := new(big.Int).SetString("111222333444555678999", 10) // "111,222,333,444,555,678,999" bb, _ := new(big.Int).SetString("-111222333444555678999", 10) // "-111,222,333,444,555,678,999" diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 796821160e..45eb4af679 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, @@ -186,7 +186,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) @@ -252,7 +252,7 @@ func Setup(ctx *cli.Context) error { handler = log.TerminalHandler(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)