easy_debug/
lib.rs

1/*!
2## This crate provide prints macros that are not compiled in releases builds.
3## Macros are enabled using ENV variable APP_DEBUG
4
5### Basic usage
6```
7use easy_debug::{dbg_print, dbg_println, dbg_eprint, dbg_eprintln};
8
9let debug_str_val = "debug string value";
10
11dbg_print!("debug_str_val");
12dbg_println!("debug_str_val = {}", debug_str_val);
13dbg_eprint!("I'm printing to the Standard Error");
14dbg_eprintln!("Print to Standard Error");
15
16```
17
18### Macros names with aliasing
19```
20use easy_debug::{
21    dbg_print as dbg_p,
22    dbg_println as dbg_pln,
23    dbg_eprint as dbg_ep,
24    dbg_eprintln as dbg_epln,
25};
26
27let debug_str_val = "debug string value";
28
29dbg_p!("debug_str_val");
30dbg_pln!("debug_str_val = {}", debug_str_val);
31dbg_ep!("I'm printing to the Standard Error");
32dbg_epln!("Print to Standard Error");
33
34```
35
36
37### Extended macros names with aliasing
38```
39use easy_debug::{
40    dbg_xprint as dbg_xp,
41    dbg_xprintln as dbg_xpln,
42    dbg_xeprint as dbg_xep,
43    dbg_exprintln as dbg_xepln,
44};
45
46let debug_str_val = "debug string value";
47
48dbg_xp!("debug_str_val");
49dbg_xpln!("debug_str_val = {}", debug_str_val);
50dbg_xep!("I'm printing to the Standard Error");
51dbg_xepln!("Print to Standard Error");
52
53```
54*/
55
56/// ----------------------------------------------------------------
57/// BASIC print, println, eprint, eprintln functions
58/// ----------------------------------------------------------------
59
60/// Prints to the standard ouput only in debug build.  
61/// In release build this macro is not compiled thanks to `#[cfg(debug_assertions)]`.  
62/// see [https://doc.rust-lang.org/std/macro.print.html](https://doc.rust-lang.org/std/macro.print.html) for more info.
63#[macro_export]
64macro_rules! dbg_print {
65    ($($message:expr),*) => {
66        if std::env::var("APP_DEBUG").is_ok() {
67            #[cfg(debug_assertions)]  print!("[DEBUG]: {}", format!($($message),*));
68        }
69    };
70}
71
72#[macro_export]
73macro_rules! dbg_println {
74    ($($message:expr),*) => {
75        if std::env::var("APP_DEBUG").is_ok() {
76            #[cfg(debug_assertions)]  println!("[DEBUG]: {}", format!($($message),*));
77        }
78    };
79}
80
81
82/// Prints to the standard error only in debug build.  
83/// In release build this macro is not compiled thanks to `#[cfg(debug_assertions)]`.  
84/// see [https://doc.rust-lang.org/std/macro.eprint.html](https://doc.rust-lang.org/std/macro.eprint.html) for more info.
85#[macro_export]
86macro_rules! dbg_eprint {
87    ($($message:expr),*) => {
88        if std::env::var("APP_DEBUG").is_ok() {
89            #[cfg(debug_assertions)]  eprint!("[DEBUG_E]: {}", format!($($message),*));
90        }
91    };
92}
93
94#[macro_export]
95macro_rules! dbg_eprintln {
96    ($($message:expr),*) => {
97        if std::env::var("APP_DEBUG").is_ok() {
98            #[cfg(debug_assertions)]  eprintln!("[DEBUG_E]: {}", format!($($message),*));
99        }
100    };
101}
102
103/// ----------------------------------------------------------------
104/// EXTENDED print, println, eprint, eprintln functions
105/// Print also module name that is calling function
106/// ----------------------------------------------------------------
107
108/// Prints to the standard ouput only in debug build.  
109/// In release build this macro is not compiled thanks to `#[cfg(debug_assertions)]`.  
110/// see [https://doc.rust-lang.org/std/macro.print.html](https://doc.rust-lang.org/std/macro.print.html) for more info.
111#[macro_export]
112macro_rules! dbg_xprint {
113    ($($message:expr),*) => {
114        if std::env::var("APP_DEBUG").is_ok() {
115            #[cfg(debug_assertions)]  print!("[DEBUG {}]: {}", module_path!(), format!($($message),*));
116        }
117    };
118}
119
120#[macro_export]
121macro_rules! dbg_xprintln {
122    ($($message:expr),*) => {
123        if std::env::var("APP_DEBUG").is_ok() {
124            #[cfg(debug_assertions)]  println!("[DEBUG {}]: {}", module_path!(), format!($($message),*));
125        }
126    };
127}
128
129/// Prints to the standard error only in debug build.  
130/// In release build this macro is not compiled thanks to `#[cfg(debug_assertions)]`.  
131/// see [https://doc.rust-lang.org/std/macro.eprint.html](https://doc.rust-lang.org/std/macro.eprint.html) for more info.
132#[macro_export]
133macro_rules! dbg_xeprint {
134    ($($message:expr),*) => {
135        if std::env::var("APP_DEBUG").is_ok() {
136            #[cfg(debug_assertions)]  eprint!("[DEBUG_E {}]: {}", module_path!(), format!($($message),*));
137        }
138    };
139}
140
141#[macro_export]
142macro_rules! dbg_xeprintln {
143    ($($message:expr),*) => {
144        if std::env::var("APP_DEBUG").is_ok() {
145            #[cfg(debug_assertions)]  eprintln!("[DEBUG_E {}]: {}", module_path!(), format!($($message),*));
146        }
147    };
148}