refactor(logger): 日志体系优化,分四类文件存储
- 认证日志 (auth.log): 登录/token/监听器注册,target=ias::auth - 消息队列日志 (queue.log): 入队/出队内容、消费路由,target=ias::queue - 工具日志 (tool.log): 调用参数/输出/耗时/工具错误,target=ias::tool - 错误日志 (error.log): 所有非工具调用的 ERROR/WARN 自动捕获 使用 tracing-subscriber 多层过滤架构,终端输出保持不变
This commit is contained in:
+8
-6
@@ -110,11 +110,11 @@ impl QueueRunner {
|
||||
|
||||
/// 启动路由主循环(阻塞,应在 tokio::spawn 中运行)
|
||||
pub async fn run(&self) {
|
||||
info!("QueueRunner 已启动");
|
||||
info!(target: "ias::queue", "QueueRunner 已启动");
|
||||
loop {
|
||||
// 检查关闭信号
|
||||
if self.shutdown.load(Ordering::Relaxed) {
|
||||
info!("QueueRunner 收到关闭信号,停止路由");
|
||||
info!(target: "ias::queue", "QueueRunner 收到关闭信号,停止路由");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -138,6 +138,7 @@ impl QueueRunner {
|
||||
|
||||
if let Err(_e) = result {
|
||||
warn!(
|
||||
target: "ias::queue",
|
||||
"路由消息失败 (target={:?}, user={}, corr={}): 通道已关闭,跳过",
|
||||
target, user_id, correlation_id
|
||||
);
|
||||
@@ -155,7 +156,7 @@ impl QueueRunner {
|
||||
}
|
||||
}
|
||||
}
|
||||
info!("QueueRunner 已停止");
|
||||
info!(target: "ias::queue", "QueueRunner 已停止");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,6 +172,7 @@ impl EnqueueHandle {
|
||||
pub async fn enqueue(&self, msg: PipelineMessage) {
|
||||
if self.shutdown.load(Ordering::Relaxed) {
|
||||
warn!(
|
||||
target: "ias::queue",
|
||||
"队列已关闭,丢弃消息: user={}",
|
||||
msg.user_id()
|
||||
);
|
||||
@@ -200,7 +202,7 @@ pub async fn drain_and_shutdown(
|
||||
runner_shutdown: &ShutdownHandle,
|
||||
consumer_handles: Vec<tokio::task::JoinHandle<()>>,
|
||||
) {
|
||||
info!("开始关闭队列系统...");
|
||||
info!(target: "ias::queue", "开始关闭队列系统...");
|
||||
|
||||
// 1. 阻止新消息入队(设置关闭标志)
|
||||
runner_shutdown.shutdown();
|
||||
@@ -211,9 +213,9 @@ pub async fn drain_and_shutdown(
|
||||
// 3. 等待消费者 task 完成
|
||||
for handle in consumer_handles {
|
||||
if let Err(e) = handle.await {
|
||||
error!("消费者 task 结束异常: {:?}", e);
|
||||
error!(target: "ias::queue", "消费者 task 结束异常: {:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
info!("队列系统已完全关闭");
|
||||
info!(target: "ias::queue", "队列系统已完全关闭");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user