Trait tracing_subscriber::util::SubscriberInitExt
source · pub trait SubscriberInitExtwhere
Self: Into<Dispatch>,{
fn set_default(self) -> DefaultGuard { ... }
fn try_init(self) -> Result<(), TryInitError> { ... }
fn init(self) { ... }
}
Expand description
Extension trait adding utility methods for subscriber initialization.
This trait provides extension methods to make configuring and setting a
default subscriber more ergonomic. It is automatically implemented for all
types that can be converted into a trace dispatcher. Since Dispatch
implements From<T>
for all T: Subscriber
, all Subscriber
implementations will implement this extension trait as well. Types which
can be converted into Subscriber
s, such as builders that construct a
Subscriber
, may implement Into<Dispatch>
, and will also receive an
implementation of this trait.
Provided Methods§
sourcefn set_default(self) -> DefaultGuard
fn set_default(self) -> DefaultGuard
Sets self
as the default subscriber in the current scope, returning a
guard that will unset it when dropped.
If the “tracing-log” feature flag is enabled, this will also initialize
a log
compatibility layer. This allows the subscriber to consume
log::Record
s as though they were tracing
Event
s.
sourcefn try_init(self) -> Result<(), TryInitError>
fn try_init(self) -> Result<(), TryInitError>
Attempts to set self
as the global default subscriber in the current
scope, returning an error if one is already set.
If the “tracing-log” feature flag is enabled, this will also attempt to
initialize a log
compatibility layer. This allows the subscriber to
consume log::Record
s as though they were tracing
Event
s.
This method returns an error if a global default subscriber has already
been set, or if a log
logger has already been set (when the
“tracing-log” feature is enabled).
sourcefn init(self)
fn init(self)
Attempts to set self
as the global default subscriber in the current
scope, panicking if this fails.
If the “tracing-log” feature flag is enabled, this will also attempt to
initialize a log
compatibility layer. This allows the subscriber to
consume log::Record
s as though they were tracing
Event
s.
This method panics if a global default subscriber has already been set,
or if a log
logger has already been set (when the “tracing-log”
feature is enabled).