mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 14:54:45 +00:00
Add CLI flag to specify the format of logs written to the logfile (#3839)
## Proposed Changes Decouple the stdout and logfile formats by adding the `--logfile-format` CLI flag. This behaves identically to the existing `--log-format` flag, but instead will only affect the logs written to the logfile. The `--log-format` flag will no longer have any effect on the contents of the logfile. ## Additional Info This avoids being a breaking change by causing `logfile-format` to default to the value of `--log-format` if it is not provided. This means that users who were previously relying on being able to use a JSON formatted logfile will be able to continue to use `--log-format JSON`. Users who want to use JSON on stdout and default logs in the logfile, will need to pass the following flags: `--log-format JSON --logfile-format DEFAULT`
This commit is contained in:
@@ -99,6 +99,15 @@ fn main() {
|
||||
.default_value("debug")
|
||||
.global(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("logfile-format")
|
||||
.long("logfile-format")
|
||||
.value_name("FORMAT")
|
||||
.help("Specifies the log format used when emitting logs to the logfile.")
|
||||
.possible_values(&["DEFAULT", "JSON"])
|
||||
.takes_value(true)
|
||||
.global(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("logfile-max-size")
|
||||
.long("logfile-max-size")
|
||||
@@ -402,6 +411,11 @@ fn run<E: EthSpec>(
|
||||
.value_of("logfile-debug-level")
|
||||
.ok_or("Expected --logfile-debug-level flag")?;
|
||||
|
||||
let logfile_format = matches
|
||||
.value_of("logfile-format")
|
||||
// Ensure that `logfile-format` defaults to the value of `log-format`.
|
||||
.or_else(|| matches.value_of("log-format"));
|
||||
|
||||
let logfile_max_size: u64 = matches
|
||||
.value_of("logfile-max-size")
|
||||
.ok_or("Expected --logfile-max-size flag")?
|
||||
@@ -452,6 +466,7 @@ fn run<E: EthSpec>(
|
||||
debug_level: String::from(debug_level),
|
||||
logfile_debug_level: String::from(logfile_debug_level),
|
||||
log_format: log_format.map(String::from),
|
||||
logfile_format: logfile_format.map(String::from),
|
||||
log_color,
|
||||
disable_log_timestamp,
|
||||
max_log_size: logfile_max_size * 1_024 * 1_024,
|
||||
|
||||
Reference in New Issue
Block a user