fix: 修复日志查询接口访问不存在字段的问题
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
- ip_address 从 context.ip 获取 - 移除不存在的 extra_data 字段 - 修复 CSV/Excel 导出中的同样问题
This commit is contained in:
@@ -117,8 +117,8 @@ async def query_logs(
|
|||||||
"method": item.method,
|
"method": item.method,
|
||||||
"status_code": item.status_code,
|
"status_code": item.status_code,
|
||||||
"duration_ms": item.duration_ms,
|
"duration_ms": item.duration_ms,
|
||||||
"ip_address": item.ip_address,
|
"ip_address": item.context.get("ip") if item.context else None,
|
||||||
"extra_data": item.extra_data,
|
"context": item.context,
|
||||||
"stack_trace": item.stack_trace,
|
"stack_trace": item.stack_trace,
|
||||||
"log_time": str(item.log_time) if item.log_time else None
|
"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:
|
for log in logs:
|
||||||
|
ip_address = log.context.get("ip") if log.context else ""
|
||||||
writer.writerow([
|
writer.writerow([
|
||||||
log.id,
|
log.id,
|
||||||
log.log_type,
|
log.log_type,
|
||||||
@@ -194,7 +195,7 @@ def export_csv(logs: list) -> StreamingResponse:
|
|||||||
log.method or "",
|
log.method or "",
|
||||||
log.status_code or "",
|
log.status_code or "",
|
||||||
log.duration_ms or "",
|
log.duration_ms or "",
|
||||||
log.ip_address or "",
|
ip_address or "",
|
||||||
str(log.log_time) if log.log_time else ""
|
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):
|
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=1, value=log.id)
|
||||||
ws.cell(row=row, column=2, value=log.log_type)
|
ws.cell(row=row, column=2, value=log.log_type)
|
||||||
ws.cell(row=row, column=3, value=log.level)
|
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=9, value=log.method or "")
|
||||||
ws.cell(row=row, column=10, value=log.status_code 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=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 "")
|
ws.cell(row=row, column=13, value=str(log.log_time) if log.log_time else "")
|
||||||
|
|
||||||
# 调整列宽
|
# 调整列宽
|
||||||
|
|||||||
Reference in New Issue
Block a user