debugrs/
lib.rs

1use once_cell::sync::Lazy;
2use std::fmt::Display;
3use std::env;
4use std::sync::Mutex;
5
6mod debugger;
7mod utils;
8
9pub mod debug_macro;
10
11pub use debugger::RsDebugger;
12
13// Global mutable default logger
14static DEFAULT_LOGGER: Lazy<Mutex<RsDebugger>> = Lazy::new(|| {
15    let label = env::var("DEBUG_DEFAULT_LABEL").unwrap_or("debugrs:default".to_string());
16    Mutex::new(RsDebugger::new(label))
17});
18
19
20/// Writes a log message to the default logger.
21///
22/// The default logger is a global mutable logger, so be careful when using it in a
23/// multithreaded environment. If you need to write logs from multiple threads, consider
24/// using a thread-local logger instead.
25/// 
26/// To set the default logger label, set the `DEBUG_DEFAULT_LABEL` environment variable.
27///
28pub fn log<T: Display>(message: T) {
29    if let Ok(mut logger) = DEFAULT_LOGGER.lock() {
30        logger.write(message.to_string());
31    }
32}