Coverage Report

Created: 2025-12-31 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/tracing-0.1.43/src/subscriber.rs
Line
Count
Source
1
//! Collects and records trace data.
2
pub use tracing_core::subscriber::*;
3
4
#[cfg(feature = "std")]
5
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
6
pub use tracing_core::dispatcher::DefaultGuard;
7
8
/// Sets this [`Subscriber`] as the default for the current thread for the
9
/// duration of a closure.
10
///
11
/// The default subscriber is used when creating a new [`Span`] or
12
/// [`Event`].
13
///
14
///
15
/// [`Span`]: super::span::Span
16
/// [`Subscriber`]: super::subscriber::Subscriber
17
/// [`Event`]: super::event::Event
18
#[cfg(feature = "std")]
19
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
20
0
pub fn with_default<T, S>(subscriber: S, f: impl FnOnce() -> T) -> T
21
0
where
22
0
    S: Subscriber + Send + Sync + 'static,
23
{
24
0
    crate::dispatcher::with_default(&crate::Dispatch::new(subscriber), f)
25
0
}
26
27
/// Sets this subscriber as the global default for the duration of the entire program.
28
/// Will be used as a fallback if no thread-local subscriber has been set in a thread (using `with_default`.)
29
///
30
/// Can only be set once; subsequent attempts to set the global default will fail.
31
/// Returns whether the initialization was successful.
32
///
33
/// Note: Libraries should *NOT* call `set_global_default()`! That will cause conflicts when
34
/// executables try to set them later.
35
///
36
/// [`Subscriber`]: super::subscriber::Subscriber
37
/// [`Event`]: super::event::Event
38
0
pub fn set_global_default<S>(subscriber: S) -> Result<(), SetGlobalDefaultError>
39
0
where
40
0
    S: Subscriber + Send + Sync + 'static,
41
{
42
0
    crate::dispatcher::set_global_default(crate::Dispatch::new(subscriber))
43
0
}
44
45
/// Sets the [`Subscriber`] as the default for the current thread for the
46
/// duration of the lifetime of the returned [`DefaultGuard`].
47
///
48
/// The default subscriber is used when creating a new [`Span`] or [`Event`].
49
///
50
/// [`Span`]: super::span::Span
51
/// [`Subscriber`]: super::subscriber::Subscriber
52
/// [`Event`]: super::event::Event
53
/// [`DefaultGuard`]: super::dispatcher::DefaultGuard
54
#[cfg(feature = "std")]
55
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
56
#[must_use = "Dropping the guard unregisters the subscriber."]
57
0
pub fn set_default<S>(subscriber: S) -> DefaultGuard
58
0
where
59
0
    S: Subscriber + Send + Sync + 'static,
60
{
61
0
    crate::dispatcher::set_default(&crate::Dispatch::new(subscriber))
62
0
}
63
64
pub use tracing_core::dispatcher::SetGlobalDefaultError;