From 9ff89f4a7d160e2ff51f34408aa9ec06278df6ad Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 24 Jan 2026 17:25:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=E8=AE=BF=E9=97=AE=E4=B8=8D?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E5=AD=97=E6=AE=B5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ip_address 从 context.ip 获取 - 移除不存在的 extra_data 字段 - 修复 CSV/Excel 导出中的同样问题 --- backend/app/routers/logs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/backend/app/routers/logs.py b/backend/app/routers/logs.py index d2da06a..d23641e 100644 --- a/backend/app/routers/logs.py +++ b/backend/app/routers/logs.py @@ -117,8 +117,8 @@ async def query_logs( "method": item.method, "status_code": item.status_code, "duration_ms": item.duration_ms, - "ip_address": item.ip_address, - "extra_data": item.extra_data, + "ip_address": item.context.get("ip") if item.context else None, + "context": item.context, "stack_trace": item.stack_trace, "log_time": str(item.log_time) if item.log_time else None } @@ -182,6 +182,7 @@ def export_csv(logs: list) -> StreamingResponse: # 写入数据 for log in logs: + ip_address = log.context.get("ip") if log.context else "" writer.writerow([ log.id, log.log_type, @@ -194,7 +195,7 @@ def export_csv(logs: list) -> StreamingResponse: log.method or "", log.status_code or "", log.duration_ms or "", - log.ip_address or "", + ip_address or "", str(log.log_time) if log.log_time else "" ]) @@ -242,6 +243,7 @@ def export_excel(logs: list) -> StreamingResponse: # 写入数据 for row, log in enumerate(logs, 2): + ip_address = log.context.get("ip") if log.context else "" ws.cell(row=row, column=1, value=log.id) ws.cell(row=row, column=2, value=log.log_type) ws.cell(row=row, column=3, value=log.level) @@ -253,7 +255,7 @@ def export_excel(logs: list) -> StreamingResponse: ws.cell(row=row, column=9, value=log.method or "") ws.cell(row=row, column=10, value=log.status_code or "") ws.cell(row=row, column=11, value=log.duration_ms or "") - ws.cell(row=row, column=12, value=log.ip_address or "") + ws.cell(row=row, column=12, value=ip_address or "") ws.cell(row=row, column=13, value=str(log.log_time) if log.log_time else "") # 调整列宽