feat(project): init

This commit is contained in:
2026-01-21 14:03:53 +08:00
commit 739234a896
10 changed files with 415 additions and 0 deletions

45
src/lib.rs Normal file
View 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()
);
}
};
}