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::{get_log_level, set_log_level, LogLevel};
101
102 #[test]
104 fn log_level_is_set_and_read_back() {
105 for level in [
106 LogLevel::None,
107 LogLevel::Error,
108 LogLevel::Warn,
109 LogLevel::Debug,
110 LogLevel::Info,
111 ] {
112 set_log_level(level);
113 assert_eq!(get_log_level(), level);
114 log_error!("error at {:?}", level);
116 log_warn!("warn at {:?}", level);
117 log_info!("info at {:?}", level);
118 log_debug!("debug at {:?}", level);
119 }
120 }
121}