#![cfg_attr(
all(doc, feature = "document-features"),
doc = ::document_features::document_features!()
)]
#![cfg_attr(all(doc, feature = "document-features"), feature(doc_cfg, doc_auto_cfg))]
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd)]
pub enum Level {
Coarse = 1,
Detail = 2,
}
#[cfg(feature = "tracing-detail")]
pub const MAX_LEVEL: Level = Level::Detail;
#[cfg(not(feature = "tracing-detail"))]
pub const MAX_LEVEL: Level = Level::Coarse;
#[cfg(feature = "tracing")]
mod enabled;
#[cfg(feature = "tracing")]
pub use enabled::{field, Span};
impl Span {
pub fn into_scope<T>(self, f: impl FnOnce() -> T) -> T {
f()
}
}
#[cfg(feature = "tracing")]
#[doc(hidden)]
pub use enabled::{metadata, Event, MetaOnlyCallsite, Metadata};
#[cfg(not(feature = "tracing"))]
mod disabled;
#[cfg(not(feature = "tracing"))]
pub use disabled::Span;
pub mod event {
#[cfg(feature = "tracing")]
pub use tracing_core::Level;
#[cfg(not(feature = "tracing"))]
#[repr(usize)]
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum Level {
TRACE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4,
}
}
#[macro_export]
macro_rules! coarse {
(target: $target:expr, $name:expr, $($field:tt)*) => {
$crate::span!(
target: $target,
$crate::Level::Coarse,
$name,
$($field)*
)
};
(target: $target:expr, $name:expr) => {
$crate::coarse!(target: $target, $name,)
};
($name:expr, $($field:tt)*) => {
$crate::span!(
target: module_path!(),
$crate::Level::Coarse,
$name,
$($field)*
)
};
($name:expr) => {$crate::coarse!($name,)};
}
#[macro_export]
macro_rules! detail {
(target: $target:expr, $name:expr, $($field:tt)*) => {
$crate::span!(
target: $target,
$crate::Level::Detail,
$name,
$($field)*
)
};
(target: $target:expr, $name:expr) => {
$crate::detail!(target: $target, $name,)
};
($name:expr, $($field:tt)*) => {
$crate::span!(
target: module_path!(),
$crate::Level::Detail,
$name,
$($field)*
)
};
($name:expr) => {$crate::coarse!($name,)};
}
#[macro_export]
macro_rules! error {
(target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::ERROR, { $($field)* }, $($arg)*)
);
(target: $target:expr, $($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::ERROR, { $($k).+ $($field)* })
);
(target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::ERROR, { ?$($k).+ $($field)* })
);
(target: $target:expr, %$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::ERROR, { %$($k).+ $($field)* })
);
(target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, $crate::event::Level::ERROR, {}, $($arg)+)
);
({ $($field:tt)+ }, $($arg:tt)+ ) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ $($field)+ },
$($arg)+
)
);
($($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ $($k).+ = $($field)*}
)
);
(?$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ ?$($k).+ = $($field)*}
)
);
(%$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ %$($k).+ = $($field)*}
)
);
($($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ $($k).+, $($field)*}
)
);
(?$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ ?$($k).+, $($field)*}
)
);
(%$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ %$($k).+, $($field)*}
)
);
(?$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ ?$($k).+ }
)
);
(%$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ %$($k).+ }
)
);
($($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{ $($k).+ }
)
);
($($arg:tt)+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::ERROR,
{},
$($arg)+
)
);
}
#[macro_export]
macro_rules! warn {
(target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::WARN, { $($field)* }, $($arg)*)
);
(target: $target:expr, $($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::WARN, { $($k).+ $($field)* })
);
(target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::WARN, { ?$($k).+ $($field)* })
);
(target: $target:expr, %$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::WARN, { %$($k).+ $($field)* })
);
(target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, $crate::event::Level::WARN, {}, $($arg)+)
);
({ $($field:tt)+ }, $($arg:tt)+ ) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ $($field)+ },
$($arg)+
)
);
($($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ $($k).+ = $($field)*}
)
);
(?$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ ?$($k).+ = $($field)*}
)
);
(%$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ %$($k).+ = $($field)*}
)
);
($($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ $($k).+, $($field)*}
)
);
(?$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ ?$($k).+, $($field)*}
)
);
(%$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ %$($k).+, $($field)*}
)
);
(?$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ ?$($k).+ }
)
);
(%$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ %$($k).+ }
)
);
($($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{ $($k).+ }
)
);
($($arg:tt)+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::WARN,
{},
$($arg)+
)
);
}
#[macro_export]
macro_rules! info {
(target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::INFO, { $($field)* }, $($arg)*)
);
(target: $target:expr, $($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::INFO, { $($k).+ $($field)* })
);
(target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::INFO, { ?$($k).+ $($field)* })
);
(target: $target:expr, %$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::INFO, { %$($k).+ $($field)* })
);
(target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, $crate::event::Level::INFO, {}, $($arg)+)
);
({ $($field:tt)+ }, $($arg:tt)+ ) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ $($field)+ },
$($arg)+
)
);
($($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ $($k).+ = $($field)*}
)
);
(?$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ ?$($k).+ = $($field)*}
)
);
(%$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ %$($k).+ = $($field)*}
)
);
($($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ $($k).+, $($field)*}
)
);
(?$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ ?$($k).+, $($field)*}
)
);
(%$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ %$($k).+, $($field)*}
)
);
(?$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ ?$($k).+ }
)
);
(%$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ %$($k).+ }
)
);
($($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{ $($k).+ }
)
);
($($arg:tt)+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::INFO,
{},
$($arg)+
)
);
}
#[macro_export]
macro_rules! debug {
(target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::DEBUG, { $($field)* }, $($arg)*)
);
(target: $target:expr, $($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::DEBUG, { $($k).+ $($field)* })
);
(target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::DEBUG, { ?$($k).+ $($field)* })
);
(target: $target:expr, %$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::DEBUG, { %$($k).+ $($field)* })
);
(target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, $crate::event::Level::DEBUG, {}, $($arg)+)
);
({ $($field:tt)+ }, $($arg:tt)+ ) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ $($field)+ },
$($arg)+
)
);
($($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ $($k).+ = $($field)*}
)
);
(?$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ ?$($k).+ = $($field)*}
)
);
(%$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ %$($k).+ = $($field)*}
)
);
($($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ $($k).+, $($field)*}
)
);
(?$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ ?$($k).+, $($field)*}
)
);
(%$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ %$($k).+, $($field)*}
)
);
(?$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ ?$($k).+ }
)
);
(%$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ %$($k).+ }
)
);
($($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{ $($k).+ }
)
);
($($arg:tt)+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::DEBUG,
{},
$($arg)+
)
);
}
#[macro_export]
macro_rules! trace {
(target: $target:expr, { $($field:tt)* }, $($arg:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::TRACE, { $($field)* }, $($arg)*)
);
(target: $target:expr, $($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::TRACE, { $($k).+ $($field)* })
);
(target: $target:expr, ?$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::TRACE, { ?$($k).+ $($field)* })
);
(target: $target:expr, %$($k:ident).+ $($field:tt)* ) => (
$crate::event!(target: $target, $crate::event::Level::TRACE, { %$($k).+ $($field)* })
);
(target: $target:expr, $($arg:tt)+ ) => (
$crate::event!(target: $target, $crate::event::Level::TRACE, {}, $($arg)+)
);
({ $($field:tt)+ }, $($arg:tt)+ ) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ $($field)+ },
$($arg)+
)
);
($($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ $($k).+ = $($field)*}
)
);
(?$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ ?$($k).+ = $($field)*}
)
);
(%$($k:ident).+ = $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ %$($k).+ = $($field)*}
)
);
($($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ $($k).+, $($field)*}
)
);
(?$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ ?$($k).+, $($field)*}
)
);
(%$($k:ident).+, $($field:tt)*) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ %$($k).+, $($field)*}
)
);
(?$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ ?$($k).+ }
)
);
(%$($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ %$($k).+ }
)
);
($($k:ident).+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{ $($k).+ }
)
);
($($arg:tt)+) => (
$crate::event!(
target: module_path!(),
$crate::event::Level::TRACE,
{},
$($arg)+
)
);
}