Disable log color when running in non-interactive mode (#7240)

#7226


  Checks whether the application is running in a terminal, or in non-interactive mode (e.g. using systemd). It will then set the value of `--log-color` to `false` when running non-interactively.
This commit is contained in:
Mac L
2025-04-04 17:14:04 +11:00
committed by GitHub
parent 0e6da0fcaf
commit 57abffcd99

View File

@@ -20,6 +20,7 @@ use lighthouse_version::VERSION;
use logging::{build_workspace_filter, crit, MetricsLayer};
use malloc_utils::configure_memory_allocator;
use std::backtrace::Backtrace;
use std::io::IsTerminal;
use std::path::PathBuf;
use std::process::exit;
use std::sync::LazyLock;
@@ -521,10 +522,15 @@ fn run<E: EthSpec>(
let log_format = matches.get_one::<String>("log-format");
let log_color = matches
.get_one::<bool>("log-color")
.copied()
.unwrap_or(true);
let log_color = if std::io::stdin().is_terminal() {
matches
.get_one::<bool>("log-color")
.copied()
.unwrap_or(true)
} else {
// Disable color when in non-interactive mode.
false
};
let logfile_color = matches.get_flag("logfile-color");