Replace logging function with a macro

This commit is contained in:
Juno Takano 2025-12-18 02:19:55 -03:00
commit 0d66b1ee7c
5 changed files with 44 additions and 44 deletions

View file

@ -1,7 +1,22 @@
pub fn log<F>(function: &F, message: &str) {
eprintln!(
"{:?} [{}] {message}",
crate::ONSET.elapsed(),
std::any::type_name_of_val(function).replace("en::", ""),
);
pub fn elog(function: &str, message: &str) {
eprintln!("{:?} [{function}] {message}", crate::ONSET.elapsed());
}
#[macro_export]
macro_rules! log {
($fmt:expr $(, $($arg:tt)+ )? ) => {{
let mut scope = std::any::type_name_of_val(&|| {})
.to_string().replace("::{{closure}}", "");
if scope.matches("::").count() > 3 {
let parts: Vec<&str> = scope.split("::").collect();
if let (Some(module) , Some(caller)) =
(parts.get(parts.len().saturating_sub(1)),
parts.get(parts.len().saturating_sub(2))) {
scope = format!("{module}::{caller}");
}
}
$crate::dev::elog(&scope, &format!($fmt $(, $($arg)+ )?));
}};
}