#[macro_export]
macro_rules! log {
($level:expr, $($args:tt)+) => {{
const METADATA: $crate::Metadata = $crate::Metadata::new(
$level,
env!("CARGO_CRATE_NAME"),
module_path!(),
file!(),
line!(),
concat!(file!(), ':', line!()),
);
if METADATA.enabled() {
$crate::Event::dispatch(
&METADATA,
$crate::fmt_args!($($args)+),
$crate::schema!($($args)+),
);
}
}};
}
#[macro_export]
macro_rules! trace {
($($arg:tt)+) => {
$crate::log!($crate::Level::Trace, $($arg)+)
};
}
#[macro_export]
macro_rules! debug {
($($arg:tt)+) => {
$crate::log!($crate::Level::Debug, $($arg)+)
};
}
#[macro_export]
macro_rules! info {
($($arg:tt)+) => {
$crate::log!($crate::Level::Info, $($arg)+)
};
}
#[macro_export]
macro_rules! warn {
($($arg:tt)+) => {
$crate::log!($crate::Level::Warn, $($arg)+)
};
}
#[macro_export]
macro_rules! error {
($($arg:tt)+) => {
$crate::log!($crate::Level::Error, $($arg)+)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! schema {
(@ { $(,)* $($val:expr),* $(,)* } $(,)*) => {
&[ $($val),* ]
};
(@ { $(,)* $($out:expr),* }, $template:literal, $($args:tt)*) => {
$crate::schema!(
@ { $($out),* }
)
};
(@ { $(,)* $($out:expr),* }, $template:literal) => {
$crate::schema!(
@ { $($out),* }
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = $val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_serde(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = $val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_serde(&$val)) },
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = ?$val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_debug(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = ?$val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_debug($val)) },
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = %$val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_display(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $($k:ident).+ = %$val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($crate::__log_stringify!($($k).+), $crate::Value::from_display(&$val)) },
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = $val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_serde(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = $val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_serde(&$val)) },
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = ?$val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_debug(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = ?$val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_debug(&$val)) },
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = %$val:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_display(&$val)) },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $k:literal = %$val:expr) => {
$crate::schema!(
@ { $($out),*, &$crate::KeyValue::new($k, $crate::Value::from_display(&$val)) },
)
};
(@ { $(,)* $($out:expr),* }, $schema:expr, $($args:tt)*) => {
$crate::schema!(
@ { $($out),*, &$schema },
$($args)*
)
};
(@ { $(,)* $($out:expr),* }, $schema:expr) => {
$crate::schema!(
@ { $($out),*, &$schema },
)
};
($($args:tt)*) => {
$crate::schema!(@ { }, $($args)*)
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! fmt_args {
() => {
None
};
($template:literal, $($args:tt)*) => {
Some(::std::format_args!($template, $($args)*))
};
($template:literal) => {
Some(::std::format_args!($template))
};
($($k:ident).+ = $val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($($k:ident).+ = $val:expr) => {
$crate::fmt_args!()
};
($($k:ident).+ = ?$val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($($k:ident).+ = ?$val:expr) => {
$crate::fmt_args!()
};
($($k:ident).+ = %$val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($($k:ident).+ = %$val:expr) => {
$crate::fmt_args!()
};
($k:literal = $val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($k:literal = $val:expr) => {
$crate::fmt_args!()
};
($k:literal = ?$val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($k:literal = ?$val:expr) => {
$crate::fmt_args!()
};
($k:literal = %$val:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($k:literal = %$val:expr) => {
$crate::fmt_args!()
};
($schema:expr, $($args:tt)*) => {
$crate::fmt_args!(
$($args)*
)
};
($schema:expr) => {
$crate::fmt_args!()
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __log_stringify {
($s:expr) => {
stringify!($s)
};
}