Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/geth: Add --log.format cli param #27001

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions internal/debug/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -120,7 +121,7 @@ var Flags = []cli.Flag{
verbosityFlag,
vmoduleFlag,
logjsonFlag,
logfmtFlag,
logFormatFlag,
logFileFlag,
backtraceAtFlag,
debugFlag,
Expand Down Expand Up @@ -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) {
log.Warn("The flag '--log.json' is deprecated, please use '--log.format=json' instead")
holiman marked this conversation as resolved.
Show resolved Hide resolved
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 != "" {
Expand Down