Coverage Report

Created: 2025-05-07 06:59

/rust/registry/src/index.crates.io-6f17d22bba15001f/tracing-0.1.41/src/subscriber.rs
Line
Count
Source (jump to first uncovered line)
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
0
{
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
/// [span]: super::span
37
/// [`Subscriber`]: super::subscriber::Subscriber
38
/// [`Event`]: super::event::Event
39
0
pub fn set_global_default<S>(subscriber: S) -> Result<(), SetGlobalDefaultError>
40
0
where
41
0
    S: Subscriber + Send + Sync + 'static,
42
0
{
43
0
    crate::dispatcher::set_global_default(crate::Dispatch::new(subscriber))
44
0
}
45
46
/// Sets the [`Subscriber`] as the default for the current thread for the
47
/// duration of the lifetime of the returned [`DefaultGuard`].
48
///
49
/// The default subscriber is used when creating a new [`Span`] or [`Event`].
50
///
51
/// [`Span`]: super::span::Span
52
/// [`Subscriber`]: super::subscriber::Subscriber
53
/// [`Event`]: super::event::Event
54
/// [`DefaultGuard`]: super::dispatcher::DefaultGuard
55
#[cfg(feature = "std")]
56
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
57
#[must_use = "Dropping the guard unregisters the subscriber."]
58
0
pub fn set_default<S>(subscriber: S) -> DefaultGuard
59
0
where
60
0
    S: Subscriber + Send + Sync + 'static,
61
0
{
62
0
    crate::dispatcher::set_default(&crate::Dispatch::new(subscriber))
63
0
}
64
65
pub use tracing_core::dispatcher::SetGlobalDefaultError;