Automatically disable colors when tracing to a file
This commit is contained in:
parent
6a075ed4b2
commit
97d1a81b7c
|
|
@ -3555,6 +3555,7 @@ name = "zebrad"
|
||||||
version = "3.0.0-alpha.0"
|
version = "3.0.0-alpha.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"abscissa_core",
|
"abscissa_core",
|
||||||
|
"atty",
|
||||||
"chrono",
|
"chrono",
|
||||||
"color-eyre",
|
"color-eyre",
|
||||||
"dirs",
|
"dirs",
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ metrics-exporter-prometheus = "0.1.0-alpha.10"
|
||||||
|
|
||||||
dirs = "3.0.1"
|
dirs = "3.0.1"
|
||||||
inferno = { version = "0.10.2", default-features = false }
|
inferno = { version = "0.10.2", default-features = false }
|
||||||
|
atty = "0.2.14"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
vergen = "3.1.0"
|
vergen = "3.1.0"
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,12 @@ impl Tracing {
|
||||||
let filter = config.filter.unwrap_or_else(|| "".to_string());
|
let filter = config.filter.unwrap_or_else(|| "".to_string());
|
||||||
let flame_root = &config.flamegraph;
|
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);
|
||||||
|
|
||||||
// Construct a tracing subscriber with the supplied filter and enable reloading.
|
// Construct a tracing subscriber with the supplied filter and enable reloading.
|
||||||
let builder = FmtSubscriber::builder()
|
let builder = FmtSubscriber::builder()
|
||||||
.with_ansi(config.use_color)
|
.with_ansi(use_color)
|
||||||
.with_env_filter(filter)
|
.with_env_filter(filter)
|
||||||
.with_filter_reloading();
|
.with_filter_reloading();
|
||||||
let filter_handle = builder.reload_handle();
|
let filter_handle = builder.reload_handle();
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,11 @@ pub struct ZebradConfig {
|
||||||
pub struct TracingSection {
|
pub struct TracingSection {
|
||||||
/// Whether to use colored terminal output, if available.
|
/// Whether to use colored terminal output, if available.
|
||||||
///
|
///
|
||||||
/// Defaults to `true`.
|
/// Colored terminal output is automatically disabled if an output stream
|
||||||
|
/// is connected to a file. (Or another non-terminal device.)
|
||||||
|
///
|
||||||
|
/// Defaults to `true`, which automatically enables colored output to
|
||||||
|
/// terminals.
|
||||||
pub use_color: bool,
|
pub use_color: bool,
|
||||||
|
|
||||||
/// The filter used for tracing events.
|
/// The filter used for tracing events.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue