Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions tracing-subscriber/src/fmt/format/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,17 @@ pub struct PrettyVisitor<'a> {
/// [`MakeVisitor`]: crate::field::MakeVisitor
#[derive(Debug)]
pub struct PrettyFields {
ansi: bool,
/// A value to override the provided `Writer`'s ANSI formatting
/// configuration.
///
/// If this is `Some`, we override the `Writer`'s ANSI setting. This is
/// necessary in order to continue supporting the deprecated
/// `PrettyFields::with_ansi` method. If it is `None`, we don't override the
/// ANSI formatting configuration (because the deprecated method was not
/// called).
// TODO: when `PrettyFields::with_ansi` is removed, we can get rid
// of this entirely.
ansi: Option<bool>,
}

// === impl Pretty ===
Expand Down Expand Up @@ -247,21 +257,34 @@ impl Default for PrettyFields {
impl PrettyFields {
/// Returns a new default [`PrettyFields`] implementation.
pub fn new() -> Self {
Self { ansi: true }
// By default, don't override the `Writer`'s ANSI colors
// configuration. We'll only do this if the user calls the
// deprecated `PrettyFields::with_ansi` method.
Self { ansi: None }
}

#[deprecated(
since = "0.3.3",
note = "Use `fmt::Subscriber::with_ansi` or `fmt::Collector::with_ansi` instead."
)]
/// Enable ANSI encoding for formatted fields.
pub fn with_ansi(self, ansi: bool) -> Self {
Self { ansi, ..self }
Self {
ansi: Some(ansi),
..self
}
}
}

impl<'a> MakeVisitor<Writer<'a>> for PrettyFields {
type Visitor = PrettyVisitor<'a>;

#[inline]
fn make_visitor(&self, target: Writer<'a>) -> Self::Visitor {
PrettyVisitor::new(target.with_ansi(self.ansi), true)
fn make_visitor(&self, mut target: Writer<'a>) -> Self::Visitor {
if let Some(ansi) = self.ansi {
target = target.with_ansi(ansi);
}
PrettyVisitor::new(target, true)
}
}

Expand Down