parallel_processor/
logging.rs1use parking_lot::Mutex;
2
3#[allow(dead_code)]
4pub enum LogLevel {
5 Info,
6 Warning,
7 Error,
8}
9
10#[macro_export]
11macro_rules! log_info {
12 ($($arg:tt)*) => {
13 crate::logging::log(crate::logging::LogLevel::Info, format!($($arg)*))
14 };
15}
16
17#[macro_export]
18macro_rules! log_warn {
19 ($($arg:tt)*) => {
20 crate::logging::log(crate::logging::LogLevel::Warning, format!($($arg)*))
21 };
22}
23
24pub(crate) static LOGGER_CALLBACK: Mutex<Option<Box<dyn Fn(LogLevel, String) + Sync + Send>>> =
25 Mutex::new(None);
26
27pub(crate) fn log(level: LogLevel, message: String) {
28 if let Some(callback) = LOGGER_CALLBACK.lock().as_ref() {
29 callback(level, message);
30 } else {
31 println!("{}", message);
32 }
33}
34
35pub fn set_logger_function(callback: impl Fn(LogLevel, String) + Sync + Send + 'static) {
36 *LOGGER_CALLBACK.lock() = Some(Box::new(callback));
37}