feat:为日志添加上限和配置防止膨胀

This commit is contained in:
SengokuCola
2026-04-25 14:45:35 +08:00
parent 8168fe0d8a
commit be2248b283
8 changed files with 232 additions and 12 deletions

View File

@@ -24,6 +24,7 @@ from .official_configs import (
EmojiConfig,
ExpressionConfig,
KeywordReactionConfig,
LogConfig,
MaimMessageConfig,
MCPConfig,
MemoryConfig,
@@ -55,7 +56,7 @@ BOT_CONFIG_PATH: Path = (CONFIG_DIR / "bot_config.toml").resolve().absolute()
MODEL_CONFIG_PATH: Path = (CONFIG_DIR / "model_config.toml").resolve().absolute()
LEGACY_ENV_PATH: Path = (PROJECT_ROOT / ".env").resolve().absolute()
MMC_VERSION: str = "1.0.0"
CONFIG_VERSION: str = "8.9.11"
CONFIG_VERSION: str = "8.9.17"
MODEL_CONFIG_VERSION: str = "1.14.2"
logger = get_logger("config")
@@ -109,6 +110,9 @@ class Config(ConfigBase):
telemetry: TelemetryConfig = Field(default_factory=TelemetryConfig)
"""遥测配置类"""
log: LogConfig = Field(default_factory=LogConfig)
"""日志配置类"""
debug: DebugConfig = Field(default_factory=DebugConfig)
"""调试配置类"""

View File

@@ -1074,6 +1074,151 @@ class ResponseSplitterConfig(ConfigBase):
"""是否在句子数量超出回复允许的最大句子数时一次性返回全部内容"""
class LogConfig(ConfigBase):
"""日志配置类"""
__ui_label__ = "日志"
__ui_icon__ = "file-text"
date_style: str = Field(
default="m-d H:i:s",
json_schema_extra={
"x-widget": "input",
"x-icon": "clock",
},
)
"""日期格式"""
log_level_style: Literal["lite", "compact", "full"] = Field(
default="lite",
json_schema_extra={
"x-widget": "select",
"x-icon": "list",
},
)
"""日志等级显示样式"""
color_text: Literal["none", "title", "full"] = Field(
default="full",
json_schema_extra={
"x-widget": "select",
"x-icon": "palette",
},
)
"""控制台日志颜色模式"""
log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(
default="INFO",
json_schema_extra={
"x-widget": "select",
"x-icon": "list-filter",
},
)
"""全局日志级别"""
console_log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(
default="INFO",
json_schema_extra={
"x-widget": "select",
"x-icon": "terminal",
},
)
"""控制台日志级别"""
file_log_level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] = Field(
default="DEBUG",
json_schema_extra={
"x-widget": "select",
"x-icon": "file-json",
},
)
"""文件日志级别"""
log_file_max_bytes: int = Field(
default=5 * 1024 * 1024,
json_schema_extra={
"x-widget": "input",
"x-icon": "hard-drive",
},
)
"""单个日志文件最大字节数"""
max_log_files: int = Field(
default=30,
json_schema_extra={
"x-widget": "input",
"x-icon": "files",
},
)
"""最多保留的主日志文件数量"""
log_cleanup_days: int = Field(
default=30,
json_schema_extra={
"x-widget": "input",
"x-icon": "calendar-days",
},
)
"""主日志文件保留天数"""
llm_request_snapshot_limit: int = Field(
default=128,
json_schema_extra={
"x-widget": "input",
"x-icon": "archive",
},
)
"""失败请求快照最多保留数量"""
maisaka_prompt_preview_limit: int = Field(
default=256,
json_schema_extra={
"x-widget": "input",
"x-icon": "panel-top",
},
)
"""每个会话最多保留的 Maisaka Prompt 预览组数"""
maisaka_reply_effect_limit: int = Field(
default=256,
json_schema_extra={
"x-widget": "input",
"x-icon": "clipboard-check",
},
)
"""每个会话最多保留的 Maisaka 回复效果记录数"""
suppress_libraries: list[str] = Field(
default_factory=lambda: [
"faiss",
"httpx",
"urllib3",
"asyncio",
"websockets",
"httpcore",
"requests",
"sqlalchemy",
"openai",
"uvicorn",
"jieba",
],
json_schema_extra={
"x-widget": "custom",
"x-icon": "volume-x",
},
)
"""完全屏蔽日志的第三方库列表"""
library_log_levels: dict[str, str] = Field(
default_factory=lambda: {"aiohttp": "WARNING"},
json_schema_extra={
"x-widget": "custom",
"x-icon": "sliders-horizontal",
},
)
"""特定第三方库的日志级别"""
class TelemetryConfig(ConfigBase):
"""遥测配置类"""
@@ -1149,6 +1294,15 @@ class DebugConfig(ConfigBase):
)
"""是否开启回复效果评分追踪,默认关闭,需要手动打开"""
record_reply_request: bool = Field(
default=False,
json_schema_extra={
"x-widget": "switch",
"x-icon": "file-json",
},
)
"""是否记录 Replyer 请求体,默认关闭"""
class ExtraPromptItem(ConfigBase):
platform: str = Field(