From ee4be2dfa9e585bcb0ea0471ce611609f4a4d862 Mon Sep 17 00:00:00 2001 From: shay7sev Date: Wed, 21 Jan 2026 17:15:01 +0800 Subject: [PATCH] fix(postgres): fix sql --- src/outputs/postgres.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/outputs/postgres.rs b/src/outputs/postgres.rs index 550e10a..f342e17 100644 --- a/src/outputs/postgres.rs +++ b/src/outputs/postgres.rs @@ -18,14 +18,15 @@ impl PostgresOutput { impl LogOutput for PostgresOutput { async fn write(&self, record: &LogRecord) { let query = r#" - INSERT INTO app_logs (log_level, message, module, created_at) - VALUES ($1, $2, $3, $4) + INSERT INTO app_logs (service_name, log_level, message, module, created_at) + VALUES ($1, $2, $3, $4, $5) "#; // 注意:这里的 write 是在后台任务中执行的,就算慢也不会阻塞主业务 // 我们忽略错误,因为如果日志系统挂了,不能让它导致业务逻辑崩溃 (Panic) // 生产环境可以考虑加一个 fallback 机制(比如降级写文件) if let Err(e) = sqlx::query(query) + .bind(&record.service_name) .bind(record.level.to_string()) .bind(&record.message) .bind(&record.module)