#[macro_export]
macro_rules! log_trace {
(target: $t:expr, $s:literal $(, $x:expr)* $(,)?) => {{
let _: &str = $t;
#[cfg(feature = "tracing")]
$crate::__private::tracing::trace!(target: $t, $s $(, $x)*);
#[cfg(feature = "log")]
$crate::__private::log::trace!(target: $t, $s $(, $x)*);
#[cfg(feature = "defmt")]
::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "tracing", feature = "log", feature = "defmt")))]
{ let _ = ($( & $x ),*); }
}};
($s:literal $(, $x:expr)* $(,)?) => {
$crate::log_trace!(target: ::core::module_path!(), $s $(, $x)*)
};
}
#[macro_export]
macro_rules! log_debug {
(target: $t:expr, $s:literal $(, $x:expr)* $(,)?) => {{
let _: &str = $t;
#[cfg(feature = "tracing")]
$crate::__private::tracing::debug!(target: $t, $s $(, $x)*);
#[cfg(feature = "log")]
$crate::__private::log::debug!(target: $t, $s $(, $x)*);
#[cfg(feature = "defmt")]
::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "tracing", feature = "log", feature = "defmt")))]
{ let _ = ($( & $x ),*); }
}};
($s:literal $(, $x:expr)* $(,)?) => {
$crate::log_debug!(target: ::core::module_path!(), $s $(, $x)*)
};
}
#[macro_export]
macro_rules! log_info {
(target: $t:expr, $s:literal $(, $x:expr)* $(,)?) => {{
let _: &str = $t;
#[cfg(feature = "tracing")]
$crate::__private::tracing::info!(target: $t, $s $(, $x)*);
#[cfg(feature = "log")]
$crate::__private::log::info!(target: $t, $s $(, $x)*);
#[cfg(feature = "defmt")]
::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "tracing", feature = "log", feature = "defmt")))]
{ let _ = ($( & $x ),*); }
}};
($s:literal $(, $x:expr)* $(,)?) => {
$crate::log_info!(target: ::core::module_path!(), $s $(, $x)*)
};
}
#[macro_export]
macro_rules! log_warn {
(target: $t:expr, $s:literal $(, $x:expr)* $(,)?) => {{
let _: &str = $t;
#[cfg(feature = "tracing")]
$crate::__private::tracing::warn!(target: $t, $s $(, $x)*);
#[cfg(feature = "log")]
$crate::__private::log::warn!(target: $t, $s $(, $x)*);
#[cfg(feature = "defmt")]
::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "tracing", feature = "log", feature = "defmt")))]
{ let _ = ($( & $x ),*); }
}};
($s:literal $(, $x:expr)* $(,)?) => {
$crate::log_warn!(target: ::core::module_path!(), $s $(, $x)*)
};
}
#[macro_export]
macro_rules! log_error {
(target: $t:expr, $s:literal $(, $x:expr)* $(,)?) => {{
let _: &str = $t;
#[cfg(feature = "tracing")]
$crate::__private::tracing::error!(target: $t, $s $(, $x)*);
#[cfg(feature = "log")]
$crate::__private::log::error!(target: $t, $s $(, $x)*);
#[cfg(feature = "defmt")]
::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "tracing", feature = "log", feature = "defmt")))]
{ let _ = ($( & $x ),*); }
}};
($s:literal $(, $x:expr)* $(,)?) => {
$crate::log_error!(target: ::core::module_path!(), $s $(, $x)*)
};
}
pub struct LogDisplay<'a, T: ?Sized>(pub &'a T);
impl<T: core::fmt::Display + ?Sized> core::fmt::Display for LogDisplay<'_, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}
#[cfg(feature = "defmt")]
impl<T: core::fmt::Display + ?Sized> defmt::Format for LogDisplay<'_, T> {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{}", defmt::Display2Format(self))
}
}
pub struct LogDebug<'a, T: ?Sized>(pub &'a T);
impl<T: core::fmt::Debug + ?Sized> core::fmt::Debug for LogDebug<'_, T> {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
self.0.fmt(f)
}
}
#[cfg(feature = "defmt")]
impl<T: core::fmt::Debug + ?Sized> defmt::Format for LogDebug<'_, T> {
fn format(&self, f: defmt::Formatter) {
defmt::write!(f, "{}", defmt::Debug2Format(self))
}
}