#![no_std]
#[doc(hidden)]
pub use consortium_log_macros::expand_captures as __expand_captures;
#[cfg(feature = "defmt")]
#[doc(hidden)]
pub use defmt::{
debug as __defmt_debug, error as __defmt_error, info as __defmt_info, trace as __defmt_trace,
warn as __defmt_warn,
};
#[cfg(feature = "tracing")]
#[doc(hidden)]
pub use tracing::{
debug as __tracing_debug, error as __tracing_error, info as __tracing_info,
trace as __tracing_trace, warn as __tracing_warn,
};
#[cfg(feature = "defmt")]
#[doc(hidden)]
#[macro_export]
macro_rules! __defmt {
(trace, $($a:tt)*) => { $crate::__defmt_trace!($($a)*) };
(debug, $($a:tt)*) => { $crate::__defmt_debug!($($a)*) };
(info, $($a:tt)*) => { $crate::__defmt_info!($($a)*) };
(warn, $($a:tt)*) => { $crate::__defmt_warn!($($a)*) };
(error, $($a:tt)*) => { $crate::__defmt_error!($($a)*) };
}
#[cfg(not(feature = "defmt"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __defmt {
($level:ident, $($a:tt)*) => {{}};
}
#[cfg(feature = "tracing")]
#[doc(hidden)]
#[macro_export]
macro_rules! __tracing {
(trace, $($a:tt)*) => { $crate::__tracing_trace!($($a)*) };
(debug, $($a:tt)*) => { $crate::__tracing_debug!($($a)*) };
(info, $($a:tt)*) => { $crate::__tracing_info!($($a)*) };
(warn, $($a:tt)*) => { $crate::__tracing_warn!($($a)*) };
(error, $($a:tt)*) => { $crate::__tracing_error!($($a)*) };
}
#[cfg(not(feature = "tracing"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __tracing {
($level:ident, $($a:tt)*) => {{}};
}
#[cfg(not(any(feature = "defmt", feature = "tracing")))]
#[doc(hidden)]
#[macro_export]
macro_rules! __disabled {
($($a:tt)*) => {{
#[allow(clippy::all)]
if false {
let _ = core::format_args!($($a)*);
}
}};
}
#[cfg(any(feature = "defmt", feature = "tracing"))]
#[doc(hidden)]
#[macro_export]
macro_rules! __disabled {
($($a:tt)*) => {{}};
}
#[macro_export]
macro_rules! trace {
($($arg:tt)*) => {{
$crate::__expand_captures!(($crate::__log) (trace) ($($arg)*));
}};
}
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => {{
$crate::__expand_captures!(($crate::__log) (debug) ($($arg)*));
}};
}
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {{
$crate::__expand_captures!(($crate::__log) (info) ($($arg)*));
}};
}
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {{
$crate::__expand_captures!(($crate::__log) (warn) ($($arg)*));
}};
}
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {{
$crate::__expand_captures!(($crate::__log) (error) ($($arg)*));
}};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __log {
($level:ident, $($arg:tt)*) => {{
$crate::__defmt!($level, $($arg)*);
$crate::__tracing!($level, $($arg)*);
$crate::__disabled!($($arg)*);
}};
}
#[cfg(test)]
#[allow(dead_code)]
fn implicit_capture_compiles_for_enabled_backends() {
let channel = 3u8;
crate::info!("captured channel {channel}");
}
#[cfg(all(test, feature = "tracing", not(feature = "defmt")))]
mod tests {
#[test]
fn every_level_forwards() {
let name = "cm33";
let channel = 3u8;
crate::trace!("no args");
crate::debug!("one arg {}", name);
crate::info!("two args {} {}", name, channel);
crate::warn!("warn {}", channel);
crate::error!("error {}", name);
crate::error!("captured channel {channel} for {name}");
crate::error!("captured {name} then positional {}", channel);
}
}