From ed2de42048ab13803c2cd69d63381c8800b8f809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Francoeur?= Date: Fri, 11 Jul 2025 10:57:01 -0400 Subject: [PATCH] only output color on terminal --- simulator/main.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/simulator/main.rs b/simulator/main.rs index 8b5e8e47b..370348cd4 100644 --- a/simulator/main.rs +++ b/simulator/main.rs @@ -14,7 +14,7 @@ use runner::{differential, watch}; use std::any::Any; use std::backtrace::Backtrace; use std::fs::OpenOptions; -use std::io::Write; +use std::io::{IsTerminal, Write}; use std::path::{Path, PathBuf}; use std::sync::{mpsc, Arc, Mutex}; use tracing_subscriber::field::MakeExt; @@ -697,7 +697,6 @@ fn run_simulation( result } -#[allow(deprecated)] fn init_logger() { let file = OpenOptions::new() .create(true) @@ -705,16 +704,20 @@ fn init_logger() { .truncate(true) .open("simulator.log") .unwrap(); + + let requires_ansi = std::io::stdout().is_terminal(); + let _ = tracing_subscriber::registry() .with( tracing_subscriber::fmt::layer() - .with_ansi(true) + .with_ansi(requires_ansi) .with_line_number(true) .without_time() .with_thread_ids(false), ) .with(EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"))) .with( + #[allow(deprecated)] tracing_subscriber::fmt::layer() .with_writer(file) .with_ansi(false)