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 <martin@swende.se>
This commit is contained in:
Adrian Sutton 2023-03-30 23:24:48 +10:00 committed by GitHub
parent 62fb7d3f85
commit 2d1492821d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,11 +52,12 @@ var (
logjsonFlag = &cli.BoolFlag{ logjsonFlag = &cli.BoolFlag{
Name: "log.json", Name: "log.json",
Usage: "Format logs with JSON", Usage: "Format logs with JSON",
Hidden: true,
Category: flags.LoggingCategory, Category: flags.LoggingCategory,
} }
logfmtFlag = &cli.BoolFlag{ logFormatFlag = &cli.StringFlag{
Name: "log.logfmt", Name: "log.format",
Usage: "Format logs with logfmt", Usage: "Log format to use (json|logfmt|terminal)",
Category: flags.LoggingCategory, Category: flags.LoggingCategory,
} }
logFileFlag = &cli.StringFlag{ logFileFlag = &cli.StringFlag{
@ -120,7 +121,7 @@ var Flags = []cli.Flag{
verbosityFlag, verbosityFlag,
vmoduleFlag, vmoduleFlag,
logjsonFlag, logjsonFlag,
logfmtFlag, logFormatFlag,
logFileFlag, logFileFlag,
backtraceAtFlag, backtraceAtFlag,
debugFlag, debugFlag,
@ -151,13 +152,25 @@ func Setup(ctx *cli.Context) error {
useColor := logFile == "" && os.Getenv("TERM") != "dumb" && (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd())) useColor := logFile == "" && os.Getenv("TERM") != "dumb" && (isatty.IsTerminal(os.Stderr.Fd()) || isatty.IsCygwinTerminal(os.Stderr.Fd()))
var logfmt log.Format var logfmt log.Format
if ctx.Bool(logjsonFlag.Name) { switch ctx.String(logFormatFlag.Name) {
case "json":
logfmt = log.JSONFormat() logfmt = log.JSONFormat()
} else if ctx.Bool(logfmtFlag.Name) { case "logfmt":
logfmt = log.LogfmtFormat() logfmt = log.LogfmtFormat()
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 { } else {
logfmt = log.TerminalFormat(useColor) logfmt = log.TerminalFormat(useColor)
} }
default:
// Unknown log format specified
return fmt.Errorf("unknown log format: %v", ctx.String(logFormatFlag.Name))
}
if logFile != "" { if logFile != "" {
var err error var err error