From 57abffcd997fc8842f6d357878c1ec23f89a2d3d Mon Sep 17 00:00:00 2001 From: Mac L Date: Fri, 4 Apr 2025 17:14:04 +1100 Subject: [PATCH] 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. --- lighthouse/src/main.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lighthouse/src/main.rs b/lighthouse/src/main.rs index 60e65e6470..66dae05326 100644 --- a/lighthouse/src/main.rs +++ b/lighthouse/src/main.rs @@ -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( let log_format = matches.get_one::("log-format"); - let log_color = matches - .get_one::("log-color") - .copied() - .unwrap_or(true); + let log_color = if std::io::stdin().is_terminal() { + matches + .get_one::("log-color") + .copied() + .unwrap_or(true) + } else { + // Disable color when in non-interactive mode. + false + }; let logfile_color = matches.get_flag("logfile-color");