Skip to content

Commit 89ba577

Browse files
committed
subscriber: feature flags that require std enable it (#1660)
## Motivation Currently, some `tracing-subscriber` dependencies in other crates use `default-features = false`, to ensure that unneeded default features of `tracing-subscriber` are not inadvertently enabled. However, some of the features those crates enable also require the `std` feature flag. The `default-features = false` config _disables_ the `std` feature, so the required features are not available. ## Solution This branch changes `tracing-subscriber`'s `fmt`, `registry`, and `env-filter` feature flags to also enable the `std` feature flag automatically. ## Alternatives As an alternative solution, we could change crates that depend on `tracing-subscriber` with `default-features = false` to also explicitly ensure that the `std` feature is enabled (which might be worth doing regardless). This is what PR #1659 does. However, I think the approach in this branch is more correct; the feature flags that require standard library support should automatically enable it. This provides a better experience for most users, who are simply adding `default-features = false` in order to avoid enabling un-needed features, not to support `no_std`, and would like enabling a feature flag to *actually* enable that feature. `no_std` users will know not to enable `registry`, `fmt`, and `env-filter` because the documentation notes that those features require the standard library.
1 parent 485fd48 commit 89ba577

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

tracing-subscriber/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ keywords = ["logging", "tracing", "metrics", "subscriber"]
2626
default = ["smallvec", "fmt", "ansi", "tracing-log", "std"]
2727
alloc = []
2828
std = ["alloc", "tracing-core/std"]
29-
env-filter = ["matchers", "regex", "lazy_static", "tracing"]
30-
fmt = ["registry"]
29+
env-filter = ["matchers", "regex", "lazy_static", "tracing", "std"]
30+
fmt = ["registry", "std"]
3131
ansi = ["fmt", "ansi_term"]
32-
registry = ["sharded-slab", "thread_local"]
32+
registry = ["sharded-slab", "thread_local", "std"]
3333
json = ["tracing-serde", "serde", "serde_json"]
3434
# Enables support for local time when using the `time` crate timestamp
3535
# formatters.

tracing-subscriber/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@
5050
//! (enabled by default).
5151
//! - `alloc`: Depend on [`liballoc`] (enabled by "std").
5252
//! - `env-filter`: Enables the [`EnvFilter`] type, which implements filtering
53-
//! similar to the [`env_logger` crate].
53+
//! similar to the [`env_logger` crate]. **Requires "std"**.
5454
//! - `fmt`: Enables the [`fmt`] module, which provides a subscriber
5555
//! implementation for printing formatted representations of trace events.
56-
//! Enabled by default.
56+
//! Enabled by default. **Requires "std"**.
5757
//! - `ansi`: Enables `fmt` support for ANSI terminal colors. Enabled by
5858
//! default.
5959
//! - `registry`: enables the [`registry`] module. Enabled by default.
60+
//! **Requires "std"**.
6061
//! - `json`: Enables `fmt` support for JSON output. In JSON output, the ANSI
61-
//! feature does nothing.
62+
//! feature does nothing. **Requires "fmt" and "std"**.
6263
//! - [`local-time`]: Enables local time formatting when using the [`time`
6364
//! crate]'s timestamp formatters with the `fmt` subscriber.
6465
//!

0 commit comments

Comments
 (0)