summaryrefslogtreecommitdiffstats
path: root/melib/src/lib.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-05-16 12:46:01 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-05-16 12:46:01 +0300
commit68b1feb6c87fbbf4dc0a42aff1aa1aab13cccfb6 (patch)
tree7f0ff257bc0df54f811943fef9c68c5d82edc64a /melib/src/lib.rs
parent295577f9d717a96a14288f1c84a04b6af6fe15c5 (diff)
melib: add timestamp to debug trace logs
Diffstat (limited to 'melib/src/lib.rs')
-rw-r--r--melib/src/lib.rs51
1 files changed, 21 insertions, 30 deletions
diff --git a/melib/src/lib.rs b/melib/src/lib.rs
index bf679a9a..6b87920b 100644
--- a/melib/src/lib.rs
+++ b/melib/src/lib.rs
@@ -37,22 +37,31 @@
//! - A `debug` macro that works like `std::dbg` but for multiple threads. (see `dbg` module)
#[macro_use]
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)]
#[macro_export]
macro_rules! debug {
($val:literal) => {
{
if cfg!(feature="debug-tracing") {
- eprint!(
- "[{:?}] {}:{}_{}: ",
- std::thread::current()
- .name()
- .map(std::string::ToString::to_string)
- .unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
- file!(),
- line!(),
- column!()
- );
+ log_tag!();
eprintln!($val);
}
$val
@@ -65,16 +74,7 @@ pub mod dbg {
// of temporaries - https://stackoverflow.com/a/48732525/1063961
match $val {
tmp => {
- eprint!(
- "[{:?}] {}:{}_{}: ",
- std::thread::current()
- .name()
- .map(std::string::ToString::to_string)
- .unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
- file!(),
- line!(),
- column!()
- );
+ log_tag!();
eprintln!("{} = {:?}", stringify, tmp);
tmp
}
@@ -85,16 +85,7 @@ pub mod dbg {
};
($fmt:literal, $($arg:tt)*) => {
if cfg!(feature="debug-tracing") {
- eprint!(
- "[{:?}] {}:{}_{}: ",
- std::thread::current()
- .name()
- .map(std::string::ToString::to_string)
- .unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
- file!(),
- line!(),
- column!()
- );
+ log_tag!();
eprintln!($fmt, $($arg)*);
}
};