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