diff --git a/zebrad/src/components/tracing/component.rs b/zebrad/src/components/tracing/component.rs index ab8015d21..a0122c230 100644 --- a/zebrad/src/components/tracing/component.rs +++ b/zebrad/src/components/tracing/component.rs @@ -21,8 +21,10 @@ impl Tracing { let filter = config.filter.unwrap_or_else(|| "".to_string()); let flame_root = &config.flamegraph; - // Only use color if tracing output is being sent to a terminal - let use_color = config.use_color && atty::is(atty::Stream::Stdout); + // Only use color if tracing output is being sent to a terminal or if it was explicitly + // forced to. + let use_color = + config.force_use_color || (config.use_color && atty::is(atty::Stream::Stdout)); // Construct a tracing subscriber with the supplied filter and enable reloading. let builder = FmtSubscriber::builder() diff --git a/zebrad/src/config.rs b/zebrad/src/config.rs index 2920a5667..b692cb0d5 100644 --- a/zebrad/src/config.rs +++ b/zebrad/src/config.rs @@ -57,6 +57,14 @@ pub struct TracingSection { /// terminals. pub use_color: bool, + /// Whether to force the use of colored terminal output, even if it's not available. + /// + /// Will force Zebra to use colored terminal output even if it does not detect that the output + /// is a terminal that supports colors. + /// + /// Defaults to `false`, which keeps the behavior of `use_color`. + pub force_use_color: bool, + /// The filter used for tracing events. /// /// The filter is used to create a `tracing-subscriber` @@ -120,6 +128,7 @@ impl Default for TracingSection { fn default() -> Self { Self { use_color: true, + force_use_color: false, filter: None, endpoint_addr: None, flamegraph: None, diff --git a/zebrad/tests/acceptance.rs b/zebrad/tests/acceptance.rs index 38af73c3e..3750f0ac7 100644 --- a/zebrad/tests/acceptance.rs +++ b/zebrad/tests/acceptance.rs @@ -42,7 +42,7 @@ use zebra_test::{ }; use zebrad::{ components::{mempool, sync}, - config::{SyncSection, ZebradConfig}, + config::{SyncSection, TracingSection, ZebradConfig}, }; /// The amount of time we wait after launching `zebrad`. @@ -82,12 +82,22 @@ fn default_test_config() -> Result { ..zebra_consensus::Config::default() }; + let force_use_color = !matches!( + env::var("ZEBRA_FORCE_USE_COLOR"), + Err(env::VarError::NotPresent) + ); + let tracing = TracingSection { + force_use_color, + ..TracingSection::default() + }; + let config = ZebradConfig { network, state: zebra_state::Config::ephemeral(), sync, mempool, consensus, + tracing, ..ZebradConfig::default() };