1#[cfg(any(feature = "native", feature = "wasm"))]
4pub mod interface;
5
6#[cfg(feature = "native")]
7pub(crate) mod native;
8#[cfg(feature = "wasm")]
9pub(crate) mod wasm;
10#[cfg(any(feature = "native", feature = "wasm"))]
11pub use interface::settings::LoggerSettings as LoggerSettings;
12#[cfg(any(feature = "native", feature = "wasm"))]
13pub use interface::logger as logger;
14#[cfg(any(feature = "native", feature = "wasm"))]
15pub use interface::logger::init as init;
16
17#[cfg(any(feature = "native", feature = "wasm"))]
29use crate::interface::settings::RUNNING_SETTINGS;
30
31#[cfg(any(feature = "native", feature = "wasm"))]
43#[doc(hidden)]
44pub fn debug_extra_enabled() -> bool {
45 let running_settings = RUNNING_SETTINGS.get().expect("better-logger: macro called before logger::init()");
46 if running_settings.debug_extra == true {
47 return true;
48 }
49 else {
50 return false;
51 }
52}
53
54#[cfg(any(feature = "native", feature = "wasm"))]
55#[doc(hidden)]
56pub fn is_async() -> bool {
57 let running_settings = RUNNING_SETTINGS.get().expect("better-logger: macro called before logger::init()");
58 if running_settings.async_logging == true {
59 return true;
60 }
61 else {
62 return false
63 }
64}
65
66#[cfg(any(feature = "native", feature = "wasm"))]
67#[doc(hidden)]
68pub fn log_async(level: &str, target: &str, msg: &str) {
69 #[cfg(feature = "native")]
70 crate::native::log::native_log_async(level, target, msg);
71
72 #[cfg(feature = "wasm")]
73 crate::wasm::log::wasm_log_async(level, target, msg);
74}
75
76#[cfg(any(feature = "native", feature = "wasm"))]
77#[doc(hidden)]
78pub fn log_sync(level: &str, target: &str, msg: &str) {
79 #[cfg(feature = "native")]
80 crate::native::log::native_log_sync(level, target, msg);
81
82 #[cfg(feature = "wasm")]
83 crate::wasm::log::wasm_log_sync(level, target, msg);
84}
85
86#[cfg(any(feature = "native", feature = "wasm"))]
98#[macro_export]
99macro_rules! trace {
100 ($($arg:tt)*) => {
101 {
102 let target = module_path!();
103 let message = format!($($arg)*);
104 if $crate::is_async() == true {
105 $crate::log_async("trace", target, &message);
106 }
107 else {
108 $crate::log_sync("trace", target, &message);
109 }
110 }
111 };
112}
113
114#[cfg(any(feature = "native", feature = "wasm"))]
115#[macro_export]
116macro_rules! debug {
117 ($($arg:tt)*) => {
118 {
119 let target = module_path!();
120 let message = format!($($arg)*);
121 if $crate::is_async() == true {
122 $crate::log_async("debug", target, &message);
123 }
124 else {
125 $crate::log_sync("debug", target, &message);
126 }
127 }
128 };
129}
130
131#[cfg(any(feature = "native", feature = "wasm"))]
132#[macro_export]
133macro_rules! debugx {
134 ($($arg:tt)*) => {
135 {
136 if $crate::debug_extra_enabled() == true {
137 let target = module_path!();
138 let message = format!($($arg)*);
139 if $crate::is_async() == true {
140 $crate::log_async("debug", target, &message);
141 } else {
142 $crate::log_sync("debug", target, &message);
143 }
144 }
145 }
146 };
147}
148
149#[cfg(any(feature = "native", feature = "wasm"))]
150#[macro_export]
151macro_rules! info {
152 ($($arg:tt)*) => {
153 {
154 let target = module_path!();
155 let message = format!($($arg)*);
156 if $crate::is_async() == true {
157 $crate::log_async("info", target, &message);
158 }
159 else {
160 $crate::log_sync("info", target, &message);
161 }
162 }
163 };
164}
165
166#[cfg(any(feature = "native", feature = "wasm"))]
167#[macro_export]
168macro_rules! warn {
169 ($($arg:tt)*) => {
170 {
171 let target = module_path!();
172 let message = format!($($arg)*);
173 if $crate::is_async() == true {
174 $crate::log_async("warn", target, &message);
175 }
176 else {
177 $crate::log_sync("warn", target, &message);
178 }
179 }
180 };
181}
182
183#[cfg(any(feature = "native", feature = "wasm"))]
184#[macro_export]
185macro_rules! error {
186 ($($arg:tt)*) => {
187 {
188 let target = module_path!();
189 let message = format!($($arg)*);
190 if $crate::is_async() == true {
191 $crate::log_async("error", target, &message);
192 }
193 else {
194 $crate::log_sync("error", target, &message);
195 }
196 }
197 };
198}