From 2d1492821d058a3488b4da2c1f62906eaf6d7c95 Mon Sep 17 00:00:00 2001 From: Adrian Sutton Date: Thu, 30 Mar 2023 23:24:48 +1000 Subject: [PATCH] cmd/geth: Add `--log.format` cli param (#27001) Removes the new --log.logfmt directive and hides --log.json, replacing both with log.format=(json|logfmt|terminal). The hidden log.json option is still respected if log.format is not specified for backwards compatibility. Co-authored-by: Martin Holst Swende --- internal/debug/flags.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/internal/debug/flags.go b/internal/debug/flags.go index 0bae9883ec..068817d532 100644 --- a/internal/debug/flags.go +++ b/internal/debug/flags.go @@ -52,11 +52,12 @@ var ( logjsonFlag = &cli.BoolFlag{ Name: "log.json", Usage: "Format logs with JSON", + Hidden: true, Category: flags.LoggingCategory, } - logfmtFlag = &cli.BoolFlag{ - Name: "log.logfmt", - Usage: "Format logs with logfmt", + logFormatFlag = &cli.StringFlag{ + Name: "log.format", + Usage: "Log format to use (json|logfmt|terminal)", Category: flags.LoggingCategory, } logFileFlag = &cli.StringFlag{ @@ -120,7 +121,7 @@ var Flags = []cli.Flag{ verbosityFlag, vmoduleFlag, logjsonFlag, - logfmtFlag, + logFormatFlag, logFileFlag, backtraceAtFlag, debugFlag, @@ -151,12 +152,24 @@ func Setup(ctx *cli.Context) error { useColor := logFile == "" && os.Getenv("TERM") != "dumb" && (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) var logfmt log.Format - if ctx.Bool(logjsonFlag.Name) { + switch ctx.String(logFormatFlag.Name) { + case "json": logfmt = log.JSONFormat() - } else if ctx.Bool(logfmtFlag.Name) { + case "logfmt": logfmt = log.LogfmtFormat() - } else { + case "terminal": logfmt = log.TerminalFormat(useColor) + case "": + // Retain backwards compatibility with `--log.json` flag if `--log.format` not set + if ctx.Bool(logjsonFlag.Name) { + defer log.Warn("The flag '--log.json' is deprecated, please use '--log.format=json' instead") + logfmt = log.JSONFormat() + } else { + logfmt = log.TerminalFormat(useColor) + } + default: + // Unknown log format specified + return fmt.Errorf("unknown log format: %v", ctx.String(logFormatFlag.Name)) } if logFile != "" {