Coverage Report

Created: 2026-02-14 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tracing-subscriber-0.3.22/src/lib.rs
Line
Count
Source
1
//! Utilities for implementing and composing [`tracing`] subscribers.
2
//!
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
8
//! functionality.
9
//!
10
//! `tracing-subscriber` is intended for use by both `Subscriber` authors and
11
//! application authors using `tracing` to instrument their applications.
12
//!
13
//! *Compiler support: [requires `rustc` 1.65+][msrv]*
14
//!
15
//! [msrv]: #supported-rust-versions
16
//!
17
//! ## `Layer`s and `Filter`s
18
//!
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.
28
//!
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.
34
//!
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
40
//!
41
//! ## Included Subscribers
42
//!
43
//! The following `Subscriber`s are provided for application authors:
44
//!
45
//! - [`fmt`] - Formats and logs tracing data (requires the `fmt` feature flag)
46
//!
47
//! ## Feature Flags
48
//!
49
//! - `std`: Enables APIs that depend 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 "registry" and "std"**.
57
//! - `ansi`: Enables `fmt` support for ANSI terminal colors. Enabled by
58
//!   default.
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.
65
//!
66
//! [`registry`]: mod@registry
67
//!
68
//! ### Optional Dependencies
69
//!
70
//! - [`tracing-log`]: Enables better formatting for events emitted by `log`
71
//!   macros in the `fmt` subscriber. Enabled by default.
72
//! - [`time`][`time` crate]: Enables support for using the [`time` crate] for timestamp
73
//!   formatting in the `fmt` subscriber.
74
//! - [`smallvec`]: Causes the `EnvFilter` type to use the `smallvec` crate (rather
75
//!   than `Vec`) as a performance optimization. Enabled by default.
76
//! - [`parking_lot`]: Use the `parking_lot` crate's `RwLock` implementation
77
//!   rather than the Rust standard library's implementation.
78
//!
79
//! ### `no_std` Support
80
//!
81
//! In embedded systems and other bare-metal applications, `tracing` can be
82
//! used without requiring the Rust standard library, although some features are
83
//! disabled. Although most of the APIs provided by `tracing-subscriber`, such
84
//! as [`fmt`] and [`EnvFilter`], require the standard library, some
85
//! functionality, such as the [`Layer`] trait, can still be used in
86
//! `no_std` environments.
87
//!
88
//! The dependency on the standard library is controlled by two crate feature
89
//! flags, "std", which enables the dependency on [`libstd`], and "alloc", which
90
//! enables the dependency on [`liballoc`] (and is enabled by the "std"
91
//! feature). These features are enabled by default, but `no_std` users can
92
//! disable them using:
93
//!
94
//! ```toml
95
//! # Cargo.toml
96
//! tracing-subscriber = { version = "0.3", default-features = false }
97
//! ```
98
//!
99
//! Additional APIs are available when [`liballoc`] is available. To enable
100
//! `liballoc` but not `std`, use:
101
//!
102
//! ```toml
103
//! # Cargo.toml
104
//! tracing-subscriber = { version = "0.3", default-features = false, features = ["alloc"] }
105
//! ```
106
//!
107
//! ### Unstable Features
108
//!
109
//! These feature flags enable **unstable** features. The public API may break in 0.1.x
110
//! releases. To enable these features, the `--cfg tracing_unstable` must be passed to
111
//! `rustc` when compiling.
112
//!
113
//! The following unstable feature flags are currently available:
114
//!
115
//! * `valuable`: Enables support for serializing values recorded using the
116
//!   [`valuable`] crate as structured JSON in the [`format::Json`] formatter.
117
//!
118
//! #### Enabling Unstable Features
119
//!
120
//! The easiest way to set the `tracing_unstable` cfg is to use the `RUSTFLAGS`
121
//! env variable when running `cargo` commands:
122
//!
123
//! ```shell
124
//! RUSTFLAGS="--cfg tracing_unstable" cargo build
125
//! ```
126
//! Alternatively, the following can be added to the `.cargo/config` file in a
127
//! project to automatically enable the cfg flag for that project:
128
//!
129
//! ```toml
130
//! [build]
131
//! rustflags = ["--cfg", "tracing_unstable"]
132
//! ```
133
//!
134
//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
135
//! [`valuable`]: https://crates.io/crates/valuable
136
//! [`format::Json`]: crate::fmt::format::Json
137
//!
138
//! ## Supported Rust Versions
139
//!
140
//! Tracing is built against the latest stable release. The minimum supported
141
//! version is 1.65. The current Tracing version is not guaranteed to build on
142
//! Rust versions earlier than the minimum supported version.
143
//!
144
//! Tracing follows the same compiler support policies as the rest of the Tokio
145
//! project. The current stable Rust compiler and the three most recent minor
146
//! versions before it will always be supported. For example, if the current
147
//! stable compiler version is 1.69, the minimum supported version will not be
148
//! increased past 1.66, three minor versions prior. Increasing the minimum
149
//! supported compiler version is not considered a semver breaking change as
150
//! long as doing so complies with this policy.
151
//!
152
//! [`Subscriber`]: tracing_core::subscriber::Subscriber
153
//! [`tracing`]: https://docs.rs/tracing/latest/tracing
154
//! [`EnvFilter`]: filter::EnvFilter
155
//! [`fmt`]: mod@fmt
156
//! [`tracing`]: https://crates.io/crates/tracing
157
//! [`tracing-log`]: https://crates.io/crates/tracing-log
158
//! [`smallvec`]: https://crates.io/crates/smallvec
159
//! [`env_logger` crate]: https://crates.io/crates/env_logger
160
//! [`parking_lot`]: https://crates.io/crates/parking_lot
161
//! [`time` crate]: https://crates.io/crates/time
162
//! [`liballoc`]: https://doc.rust-lang.org/alloc/index.html
163
//! [`libstd`]: https://doc.rust-lang.org/std/index.html
164
165
#![no_std]
166
#![doc(
167
    html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/logo-type.png",
168
    html_favicon_url = "https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/favicon.ico",
169
    issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/"
170
)]
171
#![cfg_attr(
172
    docsrs,
173
    // Allows displaying cfgs/feature flags in the documentation.
174
    feature(doc_cfg),
175
    // Allows adding traits to RustDoc's list of "notable traits"
176
    feature(doc_notable_trait),
177
    // Fail the docs build if any intra-docs links are broken
178
    deny(rustdoc::broken_intra_doc_links),
179
)]
180
#![warn(
181
    missing_debug_implementations,
182
    missing_docs,
183
    rust_2018_idioms,
184
    unreachable_pub,
185
    bad_style,
186
    dead_code,
187
    improper_ctypes,
188
    non_shorthand_field_patterns,
189
    no_mangle_generic_items,
190
    overflowing_literals,
191
    path_statements,
192
    patterns_in_fns_without_body,
193
    private_interfaces,
194
    private_bounds,
195
    unconditional_recursion,
196
    unused,
197
    unused_allocation,
198
    unused_comparisons,
199
    unused_parens,
200
    while_true
201
)]
202
// Using struct update syntax when a struct has no additional fields avoids
203
// a potential source change if additional fields are added to the struct in the
204
// future, reducing diff noise. Allow this even though clippy considers it
205
// "needless".
206
#![allow(clippy::needless_update)]
207
208
#[cfg(feature = "alloc")]
209
extern crate alloc;
210
#[cfg(feature = "std")]
211
extern crate std;
212
213
#[macro_use]
214
mod macros;
215
216
pub mod field;
217
pub mod filter;
218
pub mod prelude;
219
pub mod registry;
220
221
pub mod layer;
222
pub mod util;
223
224
feature! {
225
    #![feature = "std"]
226
    pub mod reload;
227
    pub(crate) mod sync;
228
}
229
230
feature! {
231
    #![all(feature = "fmt", feature = "std")]
232
    pub mod fmt;
233
    pub use fmt::fmt;
234
    pub use fmt::Subscriber as FmtSubscriber;
235
}
236
237
feature! {
238
    #![all(feature = "env-filter", feature = "std")]
239
    pub use filter::EnvFilter;
240
}
241
242
pub use layer::Layer;
243
244
feature! {
245
    #![all(feature = "registry", feature = "std")]
246
    pub use registry::Registry;
247
248
    /// Returns a default [`Registry`].
249
0
    pub fn registry() -> Registry {
250
0
        Registry::default()
251
0
    }
252
}
253
254
mod sealed {
255
    pub trait Sealed<A = ()> {}
256
}