sqlite_rs/
log_macros.rs

1#[macro_export]
2macro_rules! error {
3    ($($input:tt)+) => {
4        #[cfg(feature = "log")]
5        {
6            if let Some(log_level) = $crate::log::LOGGER.get() {
7                let this = $crate::log::LogLevel::Error;
8                if log_level >= &this {
9                    let mod_path = module_path!();
10                    let epoch_time = std::time::SystemTime::now()
11                    .duration_since(std::time::SystemTime::UNIX_EPOCH)
12                    .ok()
13                    .unwrap()
14                    .as_secs_f64();
15                    println!("{epoch_time:.7} {this} {mod_path}: {}", format_args!($($input)+));
16                }
17            }
18        }
19    }
20}
21
22#[macro_export]
23macro_rules! warn {
24    ($($input:tt)+) => {
25        #[cfg(feature = "log")]
26        {
27            if let Some(log_level) = $crate::log::LOGGER.get() {
28                let this = $crate::log::LogLevel::Warn;
29                if log_level >= &this {
30                    let mod_path = module_path!();
31                    let epoch_time = std::time::SystemTime::now()
32                    .duration_since(std::time::SystemTime::UNIX_EPOCH)
33                    .ok()
34                    .unwrap()
35                    .as_secs_f64();
36                    println!("{epoch_time:.7} {this} {mod_path}: {}", format_args!($($input)+));
37                }
38            }
39        }
40    }
41}
42
43#[macro_export]
44macro_rules! info {
45    ($($input:tt)+) => {
46        #[cfg(feature = "log")]
47        {
48            if let Some(log_level) = $crate::log::LOGGER.get() {
49                let this = $crate::log::LogLevel::Info;
50                if log_level >= &this {
51                    let mod_path = module_path!();
52                    let epoch_time = std::time::SystemTime::now()
53                    .duration_since(std::time::SystemTime::UNIX_EPOCH)
54                    .ok()
55                    .unwrap()
56                    .as_secs_f64();
57                    println!("{epoch_time:.7} {this} {mod_path}: {}", format_args!($($input)+));
58                }
59            }
60        }
61    }
62}
63
64#[macro_export]
65macro_rules! debug {
66    ($($input:tt)+) => {
67        #[cfg(feature = "log")]
68        {
69            if let Some(log_level) = $crate::log::LOGGER.get() {
70                let this = $crate::log::LogLevel::Debug;
71                if log_level >= &this {
72                    let mod_path = module_path!();
73                    let epoch_time = std::time::SystemTime::now()
74                    .duration_since(std::time::SystemTime::UNIX_EPOCH)
75                    .ok()
76                    .unwrap()
77                    .as_secs_f64();
78                    println!("{epoch_time:.7} {this} {mod_path}: {}", format_args!($($input)+));
79                }
80            }
81        }
82    }
83}
84
85#[macro_export]
86macro_rules! trace {
87    ($($input:tt)+) => {
88        #[cfg(feature = "log")]
89        {
90            if let Some(log_level) = $crate::log::LOGGER.get() {
91                let this = $crate::log::LogLevel::Trace;
92                if log_level >= &this {
93                    let mod_path = module_path!();
94                    let epoch_time = std::time::SystemTime::now()
95                    .duration_since(std::time::SystemTime::UNIX_EPOCH)
96                    .ok()
97                    .unwrap()
98                    .as_secs_f64();
99                    println!("{epoch_time:.7} {this} {mod_path}: {}", format_args!($($input)+));
100                }
101            }
102        }
103    }
104}