Skip to content

Commit

Permalink
subscriber: add ability to disable ANSI without crate feature
Browse files Browse the repository at this point in the history
Currently it is not possible to disable ANSI in `fmt::Subscriber`
without enabling the `ansi` crate feature. This makes it difficult for
users to implement interoperable settings that are controllable with
crate features without having to pull in the dependencies `ansi` does.

This adds a simple `fmt::Subscriber::disable_ansi()` that is available
even without the `ansi` crate feature.
  • Loading branch information
daxpedda committed Apr 14, 2023
1 parent a351b97 commit 223e47d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tracing-subscriber/src/fmt/fmt_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ impl<C, N, E, W> Subscriber<C, N, E, W> {
}
}

/// Disable ANSI terminal colors. Available even without the `ansi` crate feature.
pub fn disable_ansi(self) -> Self {
Subscriber {
is_ansi: false,
..self
}
}

/// Sets whether to write errors from [`FormatEvent`] to the writer.
/// Defaults to true.
///
Expand Down
8 changes: 8 additions & 0 deletions tracing-subscriber/src/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ where
}
}

/// Disable ANSI terminal colors. Available even without the `ansi` crate feature.
pub fn disable_ansi(self) -> CollectorBuilder<N, format::Format<L, T>, F, W> {
CollectorBuilder {
inner: self.inner.disable_ansi(),
..self
}
}

/// Sets whether to write errors from [`FormatEvent`] to the writer.
/// Defaults to true.
///
Expand Down

0 comments on commit 223e47d

Please sign in to comment.