49 lines
1.1 KiB
Rust
49 lines
1.1 KiB
Rust
// src/lib.rs
|
|
pub mod cleaner;
|
|
pub mod core;
|
|
pub mod model;
|
|
pub mod outputs;
|
|
pub use cleaner::LogCleaner;
|
|
pub mod context;
|
|
|
|
use crate::core::Logger;
|
|
use once_cell::sync::OnceCell;
|
|
use std::sync::Arc;
|
|
|
|
// 全局静态 Logger 实例
|
|
pub static GLOBAL_LOGGER: OnceCell<Arc<Logger>> = OnceCell::new();
|
|
|
|
// 初始化入口
|
|
pub fn set_global_logger(logger: Arc<Logger>) {
|
|
if GLOBAL_LOGGER.set(logger).is_err() {
|
|
eprintln!("Logger already initialized");
|
|
}
|
|
}
|
|
|
|
// 定义宏
|
|
#[macro_export]
|
|
macro_rules! log_info {
|
|
($($arg:tt)*) => {
|
|
if let Some(logger) = $crate::GLOBAL_LOGGER.get() {
|
|
logger.log(
|
|
$crate::model::LogLevel::INFO,
|
|
format!($($arg)*),
|
|
module_path!().to_string()
|
|
);
|
|
}
|
|
};
|
|
}
|
|
|
|
#[macro_export]
|
|
macro_rules! log_error {
|
|
($($arg:tt)*) => {
|
|
if let Some(logger) = $crate::GLOBAL_LOGGER.get() {
|
|
logger.log(
|
|
$crate::model::LogLevel::ERROR,
|
|
format!($($arg)*),
|
|
module_path!().to_string()
|
|
);
|
|
}
|
|
};
|
|
}
|