API Reference
tracing-subscriber
Utilities for composing tracing subscribers in Rust, including filtering and formatting layers.
Official Documentation ↗CompatibilityThis documentation covers version
v0.3. Check the official docs for the latest API surface.Installation
cargo
cargo add tracing-subscriberMethods
No methods match this filter.
tracing-subscriber filters, formats, and routes tracing events and spans to outputs.
Key Features
- EnvFilter directives from environment
- Human and JSON formatting layers
- Layered composition of subscribers
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The official API reference declares the following error types:
Error(try_init)(try_init()初始化失败时返回的错误) — official text: “Returns an Error if the initialization was unsuccessful, likely because a global subscriber was already installed by another call totry_init.” (source: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html, fetched 2026-11-08T19:20:00+08:00)panic(init)(init()的 Panics 契约(非异常类型)) — official text: “Panics if the initialization was unsuccessful, likely because a global subscriber was already installed by another call totry_init.” (source: https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html, fetched 2026-11-08T19:20:00+08:00)
API reference evidence
Fetched from official sources on 2026-11-08T19:20:00+08:00 via WebFetch https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html;WebFetch https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html.
tracing_subscriber::fmt→ signature from https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html; official text: “#### pub fn init(self) Install this Subscriber as the global default.”EnvFilter::from_default_env→ signature from https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html; official text: “#### pub fn from_default_env() -> Self Returns a newEnvFilterfrom the value of theRUST_LOGenvironment variable, ignoring any invalid filter directives.”fmt().json()→ signature from https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/struct.SubscriberBuilder.html; official text: “#### pub fn json(self) -> SubscriberBuilder<JsonFields, Format<Json, T>, F, W> where N: for<’writer> FormatFields<’writer> + ’static, Available on crate featurejsononly. Sets the subscriber being built to use a J”
FAQ
- How do I filter without RUST_LOG?
- Build an EnvFilter from a literal directive string with EnvFilter::new("info,my_crate=debug").
- Can I combine a formatter and a filter?
- Yes. Use the builder chain to attach with_env_filter and json on the same fmt subscriber.
- How do spans get recorded?
- Spans are tracked by the subscriber; the fmt layer includes span context on each event it prints.
Report a problem with this API docOpens a pre-filled issue on GitHub.