Skip to content

Commit a2ddc7b

Browse files
authored
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 6be0cc5 commit a2ddc7b

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
@@ -26,15 +26,16 @@
2626
//! (enabled by default).
2727
//! - `alloc`: Depend on [`liballoc`] (enabled by "std").
2828
//! - `env-filter`: Enables the [`EnvFilter`] type, which implements filtering
29-
//! similar to the [`env_logger` crate].
29+
//! similar to the [`env_logger` crate]. **Requires "std"**.
3030
//! - `fmt`: Enables the [`fmt`] module, which provides a subscriber
3131
//! implementation for printing formatted representations of trace events.
32-
//! Enabled by default.
32+
//! Enabled by default. **Requires "std"**.
3333
//! - `ansi`: Enables `fmt` support for ANSI terminal colors. Enabled by
3434
//! default.
3535
//! - `registry`: enables the [`registry`] module. Enabled by default.
36+
//! **Requires "std"**.
3637
//! - `json`: Enables `fmt` support for JSON output. In JSON output, the ANSI
37-
//! feature does nothing.
38+
//! feature does nothing. **Requires "fmt" and "std"**.
3839
//! - [`local-time`]: Enables local time formatting when using the [`time`
3940
//! crate]'s timestamp formatters with the `fmt` subscriber.
4041
//!

0 commit comments

Comments
 (0)