tracing_subscriber::util

Trait SubscriberInitExt

Source
pub trait SubscriberInitExt
where Self: Into<Dispatch>,
{ // Provided methods 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 Subscribers, such as builders that construct a Subscriber, may implement Into<Dispatch>, and will also receive an implementation of this trait.

Provided Methods§

Source

fn set_default(self) -> DefaultGuard

Available on crate feature std only.

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::Records as though they were tracing Events.

Source

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::Records as though they were tracing Events.

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).

Source

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::Records as though they were tracing Events.

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).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> SubscriberInitExt for T
where T: Into<Dispatch>,