From 1df9284444eb5ba98d9b755e0b86be2b19583fd3 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Mon, 30 Nov 2020 12:11:55 -0800 Subject: [PATCH] zebrad: add a use_color option to the tracing config. This is useful for creating searchable logs without having to filter color codes after the fact. --- zebrad/src/components/tracing/component.rs | 2 +- zebrad/src/config.rs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/zebrad/src/components/tracing/component.rs b/zebrad/src/components/tracing/component.rs index 3ee54aa7..0d0e56a3 100644 --- a/zebrad/src/components/tracing/component.rs +++ b/zebrad/src/components/tracing/component.rs @@ -23,7 +23,7 @@ impl Tracing { // Construct a tracing subscriber with the supplied filter and enable reloading. let builder = FmtSubscriber::builder() - .with_ansi(true) + .with_ansi(config.use_color) .with_env_filter(filter) .with_filter_reloading(); let filter_handle = builder.reload_handle(); diff --git a/zebrad/src/config.rs b/zebrad/src/config.rs index 51ac5356..a0d2b517 100644 --- a/zebrad/src/config.rs +++ b/zebrad/src/config.rs @@ -43,6 +43,11 @@ pub struct ZebradConfig { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(deny_unknown_fields, default)] pub struct TracingSection { + /// Whether to use colored terminal output, if available. + /// + /// Defaults to `true`. + pub use_color: bool, + /// The filter used for tracing events. /// /// The filter is used to create a `tracing-subscriber` @@ -101,6 +106,7 @@ pub struct TracingSection { impl Default for TracingSection { fn default() -> Self { Self { + use_color: true, filter: None, endpoint_addr: None, flamegraph: None,