serialplugin_core/
logger.rs1#[macro_export]
11macro_rules! log_error {
12 ($($arg:tt)*) => {
13 if $crate::state::get_log_level().should_log_error() {
14 #[cfg(target_os = "android")]
15 {
16 ::log::error!($($arg)*);
17 }
18 #[cfg(not(target_os = "android"))]
19 {
20 eprintln!($($arg)*);
21 }
22 }
23 };
24}
25
26#[macro_export]
28macro_rules! log_warn {
29 ($($arg:tt)*) => {
30 if $crate::state::get_log_level().should_log_warn() {
31 #[cfg(target_os = "android")]
32 {
33 ::log::warn!($($arg)*);
34 }
35 #[cfg(not(target_os = "android"))]
36 {
37 println!($($arg)*);
38 }
39 }
40 };
41}
42
43#[macro_export]
45macro_rules! log_info {
46 ($($arg:tt)*) => {
47 if $crate::state::get_log_level().should_log_info() {
48 #[cfg(target_os = "android")]
49 {
50 ::log::info!($($arg)*);
51 }
52 #[cfg(not(target_os = "android"))]
53 {
54 println!($($arg)*);
55 }
56 }
57 };
58}
59
60#[macro_export]
62macro_rules! log_debug {
63 ($($arg:tt)*) => {
64 if $crate::state::get_log_level().should_log_debug() {
65 #[cfg(target_os = "android")]
66 {
67 ::log::debug!($($arg)*);
68 }
69 #[cfg(not(target_os = "android"))]
70 {
71 println!($($arg)*);
72 }
73 }
74 };
75}
76
77#[cfg(test)]
78mod tests {
79 use crate::state::{set_log_level, LogLevel};
80
81 #[test]
82 fn test_log_level_none() {
83 set_log_level(LogLevel::None);
84 log_error!("This should not be printed");
86 log_warn!("This should not be printed");
87 log_info!("This should not be printed");
88 log_debug!("This should not be printed");
89 }
90
91 #[test]
92 fn test_log_level_error() {
93 set_log_level(LogLevel::Error);
94 log_error!("Error message");
95 }
97
98 #[test]
99 fn test_log_level_debug() {
100 set_log_level(LogLevel::Debug);
101 log_error!("Error message");
102 log_warn!("Warning message");
103 log_info!("Info message");
104 log_debug!("Debug message");
105 }
106}