summaryrefslogtreecommitdiffstats
path: root/vendor/tracing-subscriber/src/fmt/fmt_layer.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/tracing-subscriber/src/fmt/fmt_layer.rs')
-rw-r--r--vendor/tracing-subscriber/src/fmt/fmt_layer.rs28
1 files changed, 25 insertions, 3 deletions
diff --git a/vendor/tracing-subscriber/src/fmt/fmt_layer.rs b/vendor/tracing-subscriber/src/fmt/fmt_layer.rs
index 6e4e2ac0b..1e0923a54 100644
--- a/vendor/tracing-subscriber/src/fmt/fmt_layer.rs
+++ b/vendor/tracing-subscriber/src/fmt/fmt_layer.rs
@@ -273,10 +273,32 @@ impl<S, N, E, W> Layer<S, N, E, W> {
}
}
- /// Enable ANSI terminal colors for formatted output.
- #[cfg(feature = "ansi")]
- #[cfg_attr(docsrs, doc(cfg(feature = "ansi")))]
+ /// Sets whether or not the formatter emits ANSI terminal escape codes
+ /// for colors and other text formatting.
+ ///
+ /// Enabling ANSI escapes (calling `with_ansi(true)`) requires the "ansi"
+ /// crate feature flag. Calling `with_ansi(true)` without the "ansi"
+ /// feature flag enabled will panic if debug assertions are enabled, or
+ /// print a warning otherwise.
+ ///
+ /// This method itself is still available without the feature flag. This
+ /// is to allow ANSI escape codes to be explicitly *disabled* without
+ /// having to opt-in to the dependencies required to emit ANSI formatting.
+ /// This way, code which constructs a formatter that should never emit
+ /// ANSI escape codes can ensure that they are not used, regardless of
+ /// whether or not other crates in the dependency graph enable the "ansi"
+ /// feature flag.
pub fn with_ansi(self, ansi: bool) -> Self {
+ #[cfg(not(feature = "ansi"))]
+ if ansi {
+ const ERROR: &str =
+ "tracing-subscriber: the `ansi` crate feature is required to enable ANSI terminal colors";
+ #[cfg(debug_assertions)]
+ panic!("{}", ERROR);
+ #[cfg(not(debug_assertions))]
+ eprintln!("{}", ERROR);
+ }
+
Self {
is_ansi: ansi,
..self