summaryrefslogtreecommitdiffstats
path: root/melib/src/lib.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-05-01 19:20:33 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:46 +0300
commitfb406667abbd6c776c17c107b51094b0ef3f5c0d (patch)
tree89b59e8c6c2d04e4bf1f619a371a706780486863 /melib/src/lib.rs
parent9143b2e7917437d9b1c245b9fcb85928c0347404 (diff)
add debug! macro to replace eprintlns
Diffstat (limited to 'melib/src/lib.rs')
-rw-r--r--melib/src/lib.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/melib/src/lib.rs b/melib/src/lib.rs
index bf249917..0df248d2 100644
--- a/melib/src/lib.rs
+++ b/melib/src/lib.rs
@@ -18,6 +18,43 @@
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
+#[macro_use]
+pub mod dbg {
+ #[macro_export]
+ macro_rules! debug {
+ ($val:expr) => {
+ if cfg!(debug_assertions) {
+ eprint!(
+ "[{:?}] {}:{}_{}: ",
+ std::thread::current()
+ .name()
+ .map(|v| v.to_string())
+ .unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
+ file!(),
+ line!(),
+ column!()
+ );
+ eprintln!("{}", $val);
+ }
+ };
+ ($fmt:literal, $($arg:tt)*) => {
+ if cfg!(debug_assertions) {
+ eprint!(
+ "[{:?}] {}:{}_{}: ",
+ std::thread::current()
+ .name()
+ .map(|v| v.to_string())
+ .unwrap_or_else(|| format!("{:?}", std::thread::current().id())),
+ file!(),
+ line!(),
+ column!()
+ );
+ eprintln!($fmt, $($arg)*);
+ }
+ };
+ }
+}
+
pub mod addressbook;
pub mod async_workers;
pub mod conf;