pub use tracing::{debug, error, info, trace, warn};
pub use tracing::span;
pub use tracing::Level;
pub mod spans {
pub const BACKEND: &str = "canlink::backend";
pub const MESSAGE: &str = "canlink::message";
pub const FILTER: &str = "canlink::filter";
pub const QUEUE: &str = "canlink::queue";
pub const MONITOR: &str = "canlink::monitor";
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_backend_init {
($backend_name:expr) => {
tracing::info!(
target: $crate::logging::spans::BACKEND,
backend = $backend_name,
"Backend initialized"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_backend_close {
($backend_name:expr) => {
tracing::info!(
target: $crate::logging::spans::BACKEND,
backend = $backend_name,
"Backend closed"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_message_send {
($channel:expr, $id:expr) => {
tracing::debug!(
target: $crate::logging::spans::MESSAGE,
channel = $channel,
id = $id,
"Message sent"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_message_receive {
($channel:expr, $id:expr) => {
tracing::debug!(
target: $crate::logging::spans::MESSAGE,
channel = $channel,
id = $id,
"Message received"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_queue_overflow {
($policy:expr, $dropped_id:expr) => {
tracing::warn!(
target: $crate::logging::spans::QUEUE,
policy = ?$policy,
dropped_id = $dropped_id,
"Queue overflow, message dropped"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_high_frequency_warning {
($rate:expr, $threshold:expr) => {
tracing::warn!(
target: $crate::logging::spans::MESSAGE,
rate = $rate,
threshold = $threshold,
"High message frequency detected"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_connection_state_change {
($old:expr, $new:expr) => {
tracing::info!(
target: $crate::logging::spans::MONITOR,
old_state = ?$old,
new_state = ?$new,
"Connection state changed"
);
};
}
#[macro_export]
#[cfg(feature = "tracing")]
macro_rules! log_filter_match {
($filter_type:expr, $id:expr, $matched:expr) => {
tracing::trace!(
target: $crate::logging::spans::FILTER,
filter_type = $filter_type,
message_id = $id,
matched = $matched,
"Filter evaluated"
);
};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_backend_init {
($backend_name:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_backend_close {
($backend_name:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_message_send {
($channel:expr, $id:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_message_receive {
($channel:expr, $id:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_queue_overflow {
($policy:expr, $dropped_id:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_high_frequency_warning {
($rate:expr, $threshold:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_connection_state_change {
($old:expr, $new:expr) => {};
}
#[macro_export]
#[cfg(not(feature = "tracing"))]
macro_rules! log_filter_match {
($filter_type:expr, $id:expr, $matched:expr) => {};
}