From 871587594bef8ae4fe661152d4e5f1307a6a1fff Mon Sep 17 00:00:00 2001 From: Denis Cornehl Date: Mon, 12 Aug 2024 15:41:46 +0200 Subject: [PATCH] don't use ANSI escape codes when running as background service --- src/bin/cratesfyi.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/cratesfyi.rs b/src/bin/cratesfyi.rs index 0d8b46ca6..4d93610f4 100644 --- a/src/bin/cratesfyi.rs +++ b/src/bin/cratesfyi.rs @@ -1,5 +1,6 @@ use std::env; use std::fmt::Write; +use std::io::{self, IsTerminal}; use std::net::SocketAddr; use std::path::PathBuf; use std::str::FromStr; @@ -33,8 +34,13 @@ fn main() { // through rustwide. rustwide::logging::init_with(LogTracer::new()); + let is_interactive_terminal = { + let stdout = io::stdout(); + stdout.is_terminal() + }; + let tracing_registry = tracing_subscriber::registry() - .with(tracing_subscriber::fmt::layer()) + .with(tracing_subscriber::fmt::layer().with_ansi(is_interactive_terminal)) .with( EnvFilter::builder() .with_default_directive(Directive::from_str("docs_rs=info").unwrap())