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