mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-06-02 14:19:55 +08:00
feat(config): 新增错误日志请求体记录开关(默认关闭)
- 新增环境变量 ERROR_LOG_RECORD_REQUEST_BODY,默认 false - Settings 增加该配置,并在各服务写入错误日志时按开关决定是否 入库请求体,降低敏感信息泄露风险 - 配置编辑页新增对应开关,前端初始化默认值;.env.example、 README/README_ZH 同步更新 - db: add_error_log 支持 None 请求体并更稳健解析字符串/字典 - perf(db): 将错误日志批量删除 batch_size 从 500 下调到 200, 兼容 SQLite/MySQL 参数上限并提升稳定性 - docs: 补充 aliyun_oss 上传提供商与 OSS 配置示例 - style: 轻微代码格式化与导入顺序优化
This commit is contained in:
@@ -123,16 +123,19 @@ async def add_error_log(
|
||||
bool: 是否添加成功
|
||||
"""
|
||||
try:
|
||||
# 如果request_msg是字典,则转换为JSON字符串
|
||||
if isinstance(request_msg, dict):
|
||||
request_msg_json = request_msg
|
||||
elif isinstance(request_msg, str):
|
||||
try:
|
||||
request_msg_json = json.loads(request_msg)
|
||||
except json.JSONDecodeError:
|
||||
request_msg_json = {"message": request_msg}
|
||||
else:
|
||||
if request_msg is None:
|
||||
request_msg_json = None
|
||||
else:
|
||||
# 如果request_msg是字典,则转换为JSON字符串
|
||||
if isinstance(request_msg, dict):
|
||||
request_msg_json = request_msg
|
||||
elif isinstance(request_msg, str):
|
||||
try:
|
||||
request_msg_json = json.loads(request_msg)
|
||||
except json.JSONDecodeError:
|
||||
request_msg_json = {"message": request_msg}
|
||||
else:
|
||||
request_msg_json = None
|
||||
|
||||
# 插入错误日志
|
||||
query = insert(ErrorLog).values(
|
||||
@@ -455,7 +458,7 @@ async def delete_all_error_logs() -> int:
|
||||
total_deleted_count = 0
|
||||
# SQLite 对 SQL 参数数量有上限(常见为 999),IN 子句中过多参数会报错
|
||||
# 统一使用 500,兼容 SQLite/MySQL,必要时可在配置中暴露该值
|
||||
batch_size = 500
|
||||
batch_size = 200
|
||||
|
||||
try:
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user