mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-11 18:09:55 +08:00
本次提交主要包含以下更新:
- **错误日志页面增强**:
- 重构了 [`app/static/js/error_logs.js`](app/static/js/error_logs.js) 中的分页逻辑,将样式控制移至 CSS,简化了 JavaScript 代码。
- 更新了 [`app/templates/error_logs.html`](app/templates/error_logs.html) 中的分页样式,使其与 `keys_status.html` 保持一致,提升了视觉统一性。
- 在错误日志页面新增了“清空全部”按钮,方便用户一键清除所有错误记录。
- 调整了错误日志表格头部的文本颜色为白色,以改善深色主题下的可读性。
- **应用初始化与配置优化**:
- 调整了 [`app/config/config.py`](app/config/config.py) 中日志记录器的获取方式,确保在配置加载早期即可用。
- 在 [`app/core/application.py`](app/core/application.py) 中引入了更明确的数据库连接管理(连接、断开、初始化)逻辑。
- 优化了 [`app/utils/helpers.py`](app/utils/helpers.py) 中项目路径和版本文件路径的定义方式,使其在模块级别初始化。
- **依赖清理**:
- 从 [`requirements.txt`](requirements.txt) 中移除了不必要的注释。
这些更改旨在提升错误日志模块的用户体验和功能性,并优化应用程序的启动和配置管理流程。
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
"""
|
|
Service for request log operations.
|
|
"""
|
|
|
|
from datetime import datetime, timedelta, timezone
|
|
|
|
from sqlalchemy import delete
|
|
|
|
from app.database.connection import database
|
|
from app.config.config import settings
|
|
from app.database.models import RequestLog
|
|
from app.log.logger import get_request_log_logger
|
|
|
|
logger = get_request_log_logger()
|
|
|
|
|
|
async def delete_old_request_logs_task():
|
|
"""
|
|
定时删除旧的请求日志。
|
|
"""
|
|
if not settings.AUTO_DELETE_REQUEST_LOGS_ENABLED:
|
|
logger.info(
|
|
"Auto-delete for request logs is disabled by settings. Skipping task."
|
|
)
|
|
return
|
|
|
|
days_to_keep = settings.AUTO_DELETE_REQUEST_LOGS_DAYS
|
|
logger.info(
|
|
f"Starting scheduled task to delete old request logs older than {days_to_keep} days."
|
|
)
|
|
|
|
try:
|
|
cutoff_date = datetime.now(timezone.utc) - timedelta(days=days_to_keep)
|
|
|
|
query = delete(RequestLog).where(RequestLog.request_time < cutoff_date)
|
|
|
|
if not database.is_connected:
|
|
logger.info("Connecting to database for request log deletion.")
|
|
await database.connect()
|
|
|
|
result = await database.execute(query)
|
|
logger.info(
|
|
f"Request logs older than {cutoff_date} potentially deleted. Rows affected: {result.rowcount if result else 'N/A'}"
|
|
)
|
|
|
|
except Exception as e:
|
|
logger.error(
|
|
f"An error occurred during the scheduled request log deletion: {str(e)}",
|
|
exc_info=True,
|
|
)
|