Coverage Report

Created: 2025-11-24 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tracing-subscriber-0.3.20/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
#![doc(
165
    html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/main/assets/logo-type.png",
166
    issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/"
167
)]
168
#![cfg_attr(
169
    docsrs,
170
    // Allows displaying cfgs/feature flags in the documentation.
171
    feature(doc_cfg),
172
    // Allows adding traits to RustDoc's list of "notable traits"
173
    feature(doc_notable_trait),
174
    // Fail the docs build if any intra-docs links are broken
175
    deny(rustdoc::broken_intra_doc_links),
176
)]
177
#![warn(
178
    missing_debug_implementations,
179
    missing_docs,
180
    rust_2018_idioms,
181
    unreachable_pub,
182
    bad_style,
183
    dead_code,
184
    improper_ctypes,
185
    non_shorthand_field_patterns,
186
    no_mangle_generic_items,
187
    overflowing_literals,
188
    path_statements,
189
    patterns_in_fns_without_body,
190
    private_interfaces,
191
    private_bounds,
192
    unconditional_recursion,
193
    unused,
194
    unused_allocation,
195
    unused_comparisons,
196
    unused_parens,
197
    while_true
198
)]
199
// Using struct update syntax when a struct has no additional fields avoids
200
// a potential source change if additional fields are added to the struct in the
201
// future, reducing diff noise. Allow this even though clippy considers it
202
// "needless".
203
#![allow(clippy::needless_update)]
204
#![cfg_attr(not(feature = "std"), no_std)]
205
206
#[cfg(feature = "alloc")]
207
extern crate alloc;
208
209
#[macro_use]
210
mod macros;
211
212
pub mod field;
213
pub mod filter;
214
pub mod prelude;
215
pub mod registry;
216
217
pub mod layer;
218
pub mod util;
219
220
feature! {
221
    #![feature = "std"]
222
    pub mod reload;
223
    pub(crate) mod sync;
224
}
225
226
feature! {
227
    #![all(feature = "fmt", feature = "std")]
228
    pub mod fmt;
229
    pub use fmt::fmt;
230
    pub use fmt::Subscriber as FmtSubscriber;
231
}
232
233
feature! {
234
    #![all(feature = "env-filter", feature = "std")]
235
    pub use filter::EnvFilter;
236
}
237
238
pub use layer::Layer;
239
240
feature! {
241
    #![all(feature = "registry", feature = "std")]
242
    pub use registry::Registry;
243
244
    /// Returns a default [`Registry`].
245
0
    pub fn registry() -> Registry {
246
0
        Registry::default()
247
0
    }
248
}
249
250
mod sealed {
251
    pub trait Sealed<A = ()> {}
252
}