fix(postgres): fix sql

This commit is contained in:
2026-01-21 17:15:01 +08:00
parent 739234a896
commit ee4be2dfa9

View File

@@ -18,14 +18,15 @@ impl PostgresOutput {
impl LogOutput for PostgresOutput { impl LogOutput for PostgresOutput {
async fn write(&self, record: &LogRecord) { async fn write(&self, record: &LogRecord) {
let query = r#" let query = r#"
INSERT INTO app_logs (log_level, message, module, created_at) INSERT INTO app_logs (service_name, log_level, message, module, created_at)
VALUES ($1, $2, $3, $4) VALUES ($1, $2, $3, $4, $5)
"#; "#;
// 注意:这里的 write 是在后台任务中执行的,就算慢也不会阻塞主业务 // 注意:这里的 write 是在后台任务中执行的,就算慢也不会阻塞主业务
// 我们忽略错误,因为如果日志系统挂了,不能让它导致业务逻辑崩溃 (Panic) // 我们忽略错误,因为如果日志系统挂了,不能让它导致业务逻辑崩溃 (Panic)
// 生产环境可以考虑加一个 fallback 机制(比如降级写文件) // 生产环境可以考虑加一个 fallback 机制(比如降级写文件)
if let Err(e) = sqlx::query(query) if let Err(e) = sqlx::query(query)
.bind(&record.service_name)
.bind(record.level.to_string()) .bind(record.level.to_string())
.bind(&record.message) .bind(&record.message)
.bind(&record.module) .bind(&record.module)