1 //! Utilities for implementing and composing [`tracing`] subscribers.
3 //! [`tracing`] is a framework for instrumenting Rust programs to collect
4 //! scoped, structured, and async-aware diagnostics. The [`Subscriber`] trait
5 //! represents the functionality necessary to collect this trace data. This
6 //! crate contains tools for composing subscribers out of smaller units of
7 //! behaviour, and batteries-included implementations of common subscriber
10 //! `tracing-subscriber` is intended for use by both `Subscriber` authors and
11 //! application authors using `tracing` to instrument their applications.
13 //! *Compiler support: [requires `rustc` 1.42+][msrv]*
15 //! [msrv]: #supported-rust-versions
17 //! ## `Layer`s and `Filter`s
19 //! The most important component of the `tracing-subscriber` API is the
20 //! [`Layer`] trait, which provides a composable abstraction for building
21 //! [`Subscriber`]s. Like the [`Subscriber`] trait, a [`Layer`] defines a
22 //! particular behavior for collecting trace data. Unlike [`Subscriber`]s,
23 //! which implement a *complete* strategy for how trace data is collected,
24 //! [`Layer`]s provide *modular* implementations of specific behaviors.
25 //! Therefore, they can be [composed together] to form a [`Subscriber`] which is
26 //! capable of recording traces in a variety of ways. See the [`layer` module's
27 //! documentation][layer] for details on using [`Layer`]s.
29 //! In addition, the [`Filter`] trait defines an interface for filtering what
30 //! spans and events are recorded by a particular layer. This allows different
31 //! [`Layer`]s to handle separate subsets of the trace data emitted by a
32 //! program. See the [documentation on per-layer filtering][plf] for more
33 //! information on using [`Filter`]s.
35 //! [`Layer`]: crate::layer::Layer
36 //! [composed together]: crate::layer#composing-layers
37 //! [layer]: crate::layer
38 //! [`Filter`]: crate::layer::Filter
39 //! [plf]: crate::layer#per-layer-filtering
41 //! ## Included Subscribers
43 //! The following `Subscriber`s are provided for application authors:
45 //! - [`fmt`] - Formats and logs tracing data (requires the `fmt` feature flag)
49 //! - `std`: Enables APIs that depend on the on the Rust standard library
50 //! (enabled by default).
51 //! - `alloc`: Depend on [`liballoc`] (enabled by "std").
52 //! - `env-filter`: Enables the [`EnvFilter`] type, which implements filtering
53 //! similar to the [`env_logger` crate]. **Requires "std"**.
54 //! - `fmt`: Enables the [`fmt`] module, which provides a subscriber
55 //! implementation for printing formatted representations of trace events.
56 //! Enabled by default. **Requires "std"**.
57 //! - `ansi`: Enables `fmt` support for ANSI terminal colors. Enabled by
59 //! - `registry`: enables the [`registry`] module. Enabled by default.
60 //! **Requires "std"**.
61 //! - `json`: Enables `fmt` support for JSON output. In JSON output, the ANSI
62 //! feature does nothing. **Requires "fmt" and "std"**.
63 //! - [`local-time`]: Enables local time formatting when using the [`time`
64 //! crate]'s timestamp formatters with the `fmt` subscriber.
66 //! ### Optional Dependencies
68 //! - [`tracing-log`]: Enables better formatting for events emitted by `log`
69 //! macros in the `fmt` subscriber. Enabled by default.
70 //! - [`time`][`time` crate]: Enables support for using the [`time` crate] for timestamp
71 //! formatting in the `fmt` subscriber.
72 //! - [`smallvec`]: Causes the `EnvFilter` type to use the `smallvec` crate (rather
73 //! than `Vec`) as a performance optimization. Enabled by default.
74 //! - [`parking_lot`]: Use the `parking_lot` crate's `RwLock` implementation
75 //! rather than the Rust standard library's implementation.
77 //! ### `no_std` Support
79 //! In embedded systems and other bare-metal applications, `tracing` can be
80 //! used without requiring the Rust standard library, although some features are
81 //! disabled. Although most of the APIs provided by `tracing-subscriber`, such
82 //! as [`fmt`] and [`EnvFilter`], require the standard library, some
83 //! functionality, such as the [`Subscriber`] trait, can still be used in
84 //! `no_std` environments.
86 //! The dependency on the standard library is controlled by two crate feature
87 //! flags, "std", which enables the dependency on [`libstd`], and "alloc", which
88 //! enables the dependency on [`liballoc`] (and is enabled by the "std"
89 //! feature). These features are enabled by default, but `no_std` users can
90 //! disable them using:
94 //! tracing-subscriber = { version = "0.3", default-features = false }
97 //! Additional APIs are available when [`liballoc`] is available. To enable
98 //! `liballoc` but not `std`, use:
102 //! tracing-subscriber = { version = "0.3", default-features = false, features = ["alloc"] }
105 //! ## Supported Rust Versions
107 //! Tracing is built against the latest stable release. The minimum supported
108 //! version is 1.42. The current Tracing version is not guaranteed to build on
109 //! Rust versions earlier than the minimum supported version.
111 //! Tracing follows the same compiler support policies as the rest of the Tokio
112 //! project. The current stable Rust compiler and the three most recent minor
113 //! versions before it will always be supported. For example, if the current
114 //! stable compiler version is 1.45, the minimum supported version will not be
115 //! increased past 1.42, three minor versions prior. Increasing the minimum
116 //! supported compiler version is not considered a semver breaking change as
117 //! long as doing so complies with this policy.
119 //! [`tracing`]: https://docs.rs/tracing/latest/tracing/
120 //! [`Subscriber`]: https://docs.rs/tracing-core/latest/tracing_core/subscriber/trait.Subscriber.html
121 //! [`EnvFilter`]: filter/struct.EnvFilter.html
122 //! [`fmt`]: fmt/index.html
123 //! [`tracing-log`]: https://crates.io/crates/tracing-log
124 //! [`smallvec`]: https://crates.io/crates/smallvec
125 //! [`env_logger` crate]: https://crates.io/crates/env_logger
126 //! [`parking_lot`]: https://crates.io/crates/parking_lot
127 //! [`time` crate]: https://crates.io/crates/time
128 //! [`liballoc`]: https://doc.rust-lang.org/alloc/index.html
129 #![doc(html_root_url = "https://docs.rs/tracing-subscriber/0.3.1")]
131 html_logo_url
= "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png",
132 issue_tracker_base_url
= "https://github.com/tokio-rs/tracing/issues/"
136 // Allows displaying cfgs/feature flags in the documentation.
138 // Allows adding traits to RustDoc's list of "notable traits"
139 feature(doc_notable_trait
),
140 // Fail the docs build if any intra-docs links are broken
141 deny(rustdoc
::broken_intra_doc_links
),
144 missing_debug_implementations
,
152 non_shorthand_field_patterns
,
153 no_mangle_generic_items
,
154 overflowing_literals
,
156 patterns_in_fns_without_body
,
158 unconditional_recursion
,
165 // Using struct update syntax when a struct has no additional fields avoids
166 // a potential source change if additional fields are added to the struct in the
167 // future, reducing diff noise. Allow this even though clippy considers it
169 #![allow(clippy::needless_update)]
170 #![cfg_attr(not(feature = "std"), no_std)]
172 #[cfg(feature = "alloc")]
193 #![all(feature = "fmt", feature = "std")]
196 pub use fmt
::Subscriber
as FmtSubscriber
;
200 #![all(feature = "env-filter", feature = "std")]
201 pub use filter
::EnvFilter
;
204 pub use layer
::Layer
;
207 #![all(feature = "registry", feature = "std")]
208 pub use registry
::Registry
;
211 pub fn registry() -> Registry
{
217 pub trait Sealed
<A
= ()> {}