mirror of
https://git.meli.delivery/meli/meli
synced 2024-11-10 19:10:57 +00:00
melib: add timestamp to debug trace logs
This commit is contained in:
parent
295577f9d7
commit
68b1feb6c8
@ -37,22 +37,31 @@
|
|||||||
//! - A `debug` macro that works like `std::dbg` but for multiple threads. (see `dbg` module)
|
//! - A `debug` macro that works like `std::dbg` but for multiple threads. (see `dbg` module)
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod dbg {
|
pub mod dbg {
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! log_tag {
|
||||||
|
() => {
|
||||||
|
eprint!(
|
||||||
|
"[{}][{:?}] {}:{}_{}: ",
|
||||||
|
crate::datetime::timestamp_to_string(crate::datetime::now(), Some("%Y-%m-%d %T")),
|
||||||
|
std::thread::current()
|
||||||
|
.name()
|
||||||
|
.map(std::string::ToString::to_string)
|
||||||
|
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
|
||||||
|
file!(),
|
||||||
|
line!(),
|
||||||
|
column!()
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(clippy::redundant_closure)]
|
#[allow(clippy::redundant_closure)]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! debug {
|
macro_rules! debug {
|
||||||
($val:literal) => {
|
($val:literal) => {
|
||||||
{
|
{
|
||||||
if cfg!(feature="debug-tracing") {
|
if cfg!(feature="debug-tracing") {
|
||||||
eprint!(
|
log_tag!();
|
||||||
"[{:?}] {}:{}_{}: ",
|
|
||||||
std::thread::current()
|
|
||||||
.name()
|
|
||||||
.map(std::string::ToString::to_string)
|
|
||||||
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
column!()
|
|
||||||
);
|
|
||||||
eprintln!($val);
|
eprintln!($val);
|
||||||
}
|
}
|
||||||
$val
|
$val
|
||||||
@ -65,16 +74,7 @@ pub mod dbg {
|
|||||||
// of temporaries - https://stackoverflow.com/a/48732525/1063961
|
// of temporaries - https://stackoverflow.com/a/48732525/1063961
|
||||||
match $val {
|
match $val {
|
||||||
tmp => {
|
tmp => {
|
||||||
eprint!(
|
log_tag!();
|
||||||
"[{:?}] {}:{}_{}: ",
|
|
||||||
std::thread::current()
|
|
||||||
.name()
|
|
||||||
.map(std::string::ToString::to_string)
|
|
||||||
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
column!()
|
|
||||||
);
|
|
||||||
eprintln!("{} = {:?}", stringify, tmp);
|
eprintln!("{} = {:?}", stringify, tmp);
|
||||||
tmp
|
tmp
|
||||||
}
|
}
|
||||||
@ -85,16 +85,7 @@ pub mod dbg {
|
|||||||
};
|
};
|
||||||
($fmt:literal, $($arg:tt)*) => {
|
($fmt:literal, $($arg:tt)*) => {
|
||||||
if cfg!(feature="debug-tracing") {
|
if cfg!(feature="debug-tracing") {
|
||||||
eprint!(
|
log_tag!();
|
||||||
"[{:?}] {}:{}_{}: ",
|
|
||||||
std::thread::current()
|
|
||||||
.name()
|
|
||||||
.map(std::string::ToString::to_string)
|
|
||||||
.unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
|
|
||||||
file!(),
|
|
||||||
line!(),
|
|
||||||
column!()
|
|
||||||
);
|
|
||||||
eprintln!($fmt, $($arg)*);
|
eprintln!($fmt, $($arg)*);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user