feat(project): init
This commit is contained in:
45
src/lib.rs
Normal file
45
src/lib.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
// src/lib.rs
|
||||
pub mod core;
|
||||
pub mod model;
|
||||
pub mod outputs;
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user