Replace logging function with a macro
This commit is contained in:
parent
99b9feeb95
commit
0d66b1ee7c
5 changed files with 44 additions and 44 deletions
27
src/dev.rs
27
src/dev.rs
|
|
@ -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)+ )?));
|
||||
}};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue