一些Log格式错误被删除

This commit is contained in:
2025-11-07 15:52:06 +08:00
parent a1b3f51b61
commit 477fbf1876
6 changed files with 19 additions and 17 deletions

View File

@@ -76,7 +76,7 @@ async def root():
@app.exception_handler(Exception) @app.exception_handler(Exception)
async def global_exception_handler(request, exc): async def global_exception_handler(request, exc):
"""全局异常处理""" """全局异常处理"""
config.Log("Error", f"未捕获的异常: {exc}", exc_info=True) config.Log("Error", f"未捕获的异常: {exc}\n{format_traceback_info()}")
return JSONResponse( return JSONResponse(
status_code=500, status_code=500,
content={"error": "Internal Server Error", "detail": str(exc)} content={"error": "Internal Server Error", "detail": str(exc)}

View File

@@ -1,8 +1,6 @@
"""SQLite数据库操作模块 - 使用标准库sqlite3""" """SQLite数据库操作模块 - 使用标准库sqlite3"""
import sqlite3 import sqlite3
import json from ..Convention.Runtime.Config import *
import time
from typing import *
from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
from ..Convention.Runtime.Architecture import Architecture from ..Convention.Runtime.Architecture import Architecture
from ..Convention.Runtime.File import ToolFile from ..Convention.Runtime.File import ToolFile
@@ -51,7 +49,7 @@ class Database:
config.Log("Info", f"{ConsoleFrontColor.GREEN}数据库连接成功: {self.db_path}{ConsoleFrontColor.RESET}") config.Log("Info", f"{ConsoleFrontColor.GREEN}数据库连接成功: {self.db_path}{ConsoleFrontColor.RESET}")
except Exception as e: except Exception as e:
config.Log("Error", f"{ConsoleFrontColor.RED}数据库连接失败: {e}{ConsoleFrontColor.RESET}", exc_info=True) config.Log("Error", f"{ConsoleFrontColor.RED}数据库连接失败: {e}{ConsoleFrontColor.RESET}")
raise raise
return self._conn return self._conn

View File

@@ -3,7 +3,7 @@ import asyncio
from starlette.middleware.base import BaseHTTPMiddleware from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request from starlette.requests import Request
from starlette.responses import Response from starlette.responses import Response
from ..Convention.Runtime.GlobalConfig import ProjectConfig from ..Convention.Runtime.GlobalConfig import *
config = ProjectConfig() config = ProjectConfig()
MAX_CONCURRENT_REQUESTS = config.FindItem("max_concurrent_requests", 100) MAX_CONCURRENT_REQUESTS = config.FindItem("max_concurrent_requests", 100)
@@ -24,7 +24,7 @@ class ConcurrencyLimitMiddleware(BaseHTTPMiddleware):
response = await call_next(request) response = await call_next(request)
return response return response
except Exception as e: except Exception as e:
config.Log("Error", f"请求处理错误: {e}", exc_info=True) config.Log("Error", f"{ConsoleFrontColor.RED}请求处理错误: {e}{ConsoleFrontColor.RESET}")
return Response( return Response(
content='{"error": "Internal Server Error"}', content='{"error": "Internal Server Error"}',
status_code=500, status_code=500,

View File

@@ -30,7 +30,7 @@ class PluginInterface(ABC):
chat_id: 会话ID chat_id: 会话ID
user_id: 用户ID user_id: 用户ID
''' '''
config.Log("Warning", f"插件{self.__class__.__name__}未实现callback方法") config.Log("Warning", f"{ConsoleFrontColor.YELLOW}插件{self.__class__.__name__}未实现callback方法{ConsoleFrontColor.RESET}")
return "" return ""
def execute(self, path:str) -> Optional[APIRouter]: def execute(self, path:str) -> Optional[APIRouter]:
@@ -45,9 +45,13 @@ class PluginInterface(ABC):
db = get_db() db = get_db()
db_model = self.register_db_model() db_model = self.register_db_model()
if db_model: if db_model:
db.define_table(db_model.table_name) cursor = db.conn.cursor()
for name, field_def in db_model.column_defs.items(): sql = f"CREATE TABLE IF NOT EXISTS {db_model.table_name} ({', '.join([f'{name} {field_def}' for name, field_def in db_model.column_defs.items()])})"
db.define_column(db_model.table_name, name, field_def) config.Log("Info", f"{ConsoleFrontColor.LIGHTMAGENTA_EX}为表 {db_model.table_name} 创建: {sql}{ConsoleFrontColor.RESET}")
try:
cursor.execute(sql)
except Exception as e:
config.Log("Error", f"{ConsoleFrontColor.RED}为表 {db_model.table_name} 创建失败: {e}{ConsoleFrontColor.RESET}")
return router return router
@@ -77,16 +81,16 @@ class PluginInterface(ABC):
将插件注册, 使其可以被命令匹配 将插件注册, 使其可以被命令匹配
''' '''
if command in PluginInterface.plugin_instances: if command in PluginInterface.plugin_instances:
config.Log("Warning", f"插件{PluginInterface.plugin_instances[command].__class__.__name__}已注册命令{command}, 将被新插件{self.__class__.__name__}覆盖") config.Log("Warning", f"{ConsoleFrontColor.YELLOW}插件{PluginInterface.plugin_instances[command].__class__.__name__}已注册命令{command}, 将被新插件{self.__class__.__name__}覆盖{ConsoleFrontColor.RESET}")
else: else:
config.Log("Info", f"插件{self.__class__.__name__}已注册命令{command}") config.Log("Info", f"插件{self.__class__.__name__}已注册命令{command}")
PluginInterface.plugin_instances[command] = self PluginInterface.plugin_instances[command] = self
def register_db_model(self) -> DatabaseModel: def register_db_model(self) -> Optional[DatabaseModel]:
''' '''
继承后重写该方法注册数据库模型 继承后重写该方法注册数据库模型
''' '''
return DatabaseModel() return None
def is_enable_plugin(self) -> bool: def is_enable_plugin(self) -> bool:
''' '''

View File

@@ -1,5 +1,5 @@
"""Callback路由处理""" """Callback路由处理"""
from ..Convention.Runtime.GlobalConfig import ProjectConfig from ..Convention.Runtime.GlobalConfig import *
from fastapi import APIRouter, Request from fastapi import APIRouter, Request
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
@@ -103,6 +103,6 @@ async def handle_command(command: str, message: str,
else: else:
return f"❌ 未识别指令: {command}" return f"❌ 未识别指令: {command}"
except Exception as e: except Exception as e:
config.Log("Error", f"处理指令异常: {e}", exc_info=True) config.Log("Error", f"{ConsoleFrontColor.RED}处理指令异常: {e}{ConsoleFrontColor.RESET}")
return f"❌ 处理指令时出错: {str(e)}" return f"❌ 处理指令时出错: {str(e)}"

View File

@@ -53,7 +53,7 @@ async def system_stats():
} }
}) })
except Exception as e: except Exception as e:
config.Log("Error", f"{ConsoleFrontColor.RED}获取系统统计失败: {e}{ConsoleFrontColor.RESET}", exc_info=True) config.Log("Error", f"{ConsoleFrontColor.RED}获取系统统计失败: {e}{ConsoleFrontColor.RESET}")
return JSONResponse( return JSONResponse(
status_code=500, status_code=500,
content={"error": str(e)} content={"error": str(e)}