mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
fix(code-review): 参考建议修改
This commit is contained in:
+25
-16
@@ -1,30 +1,39 @@
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
from astrbot.api import logger as astrbot_logger
|
||||
|
||||
|
||||
class PluginLoggerAdapter(logging.LoggerAdapter):
|
||||
class PluginLogger:
|
||||
"""
|
||||
日志适配器:插件级统一日志装饰器
|
||||
日志代理类:插件级统一日志装饰器
|
||||
|
||||
自动向所有通过该实例输出的日志信息前缀添加 `[QQ群分析]` 标签,
|
||||
以便用户在 AstrBot 混合日志流中快速定位属于本插件的输出。
|
||||
不直接继承 logging.LoggerAdapter 以符合框架规范。
|
||||
"""
|
||||
|
||||
def process(self, msg: str, kwargs: Any) -> tuple[str, Any]:
|
||||
"""
|
||||
加工日志消息,注入插件专有前缀。
|
||||
def __init__(self, prefix: str = "[QQ群分析]"):
|
||||
self.prefix = prefix
|
||||
|
||||
Args:
|
||||
msg (str): 原始日志消息
|
||||
kwargs (Any): 额外的日志参数映射
|
||||
def _format_msg(self, msg: str) -> str:
|
||||
return f"{self.prefix} {msg}"
|
||||
|
||||
Returns:
|
||||
tuple[str, Any]: (格式化后的消息, 参数)
|
||||
"""
|
||||
return f"[QQ群分析] {msg}", kwargs
|
||||
def info(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.info(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
def error(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.error(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
def warning(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.warning(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
def debug(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.debug(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
def critical(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.critical(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
def exception(self, msg: str, *args, **kwargs):
|
||||
astrbot_logger.exception(self._format_msg(msg), *args, **kwargs)
|
||||
|
||||
|
||||
# 导出带前缀的 logger
|
||||
logger = PluginLoggerAdapter(astrbot_logger, {})
|
||||
logger = PluginLogger()
|
||||
|
||||
@@ -6,6 +6,7 @@ PDF工具模块
|
||||
import asyncio
|
||||
import sys
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from .logger import logger
|
||||
@@ -72,9 +73,6 @@ class PDFInstaller:
|
||||
|
||||
logger.info("第一步完成。正在检查浏览器内核...")
|
||||
|
||||
# 2. 检查自定义路径:若用户已手动提供内核,则跳过下载步骤
|
||||
from pathlib import Path
|
||||
|
||||
custom_path = config_manager.get_browser_path()
|
||||
if custom_path and Path(custom_path).exists():
|
||||
logger.info(f"检测到自定义浏览器路径: {custom_path}。跳过内核下载。")
|
||||
@@ -127,7 +125,7 @@ class PDFInstaller:
|
||||
@staticmethod
|
||||
async def _background_playwright_install() -> None:
|
||||
"""
|
||||
底层宿主任务:驱动系统 shell 执行浏览器二进制文件部署。
|
||||
底层宿主任务:驱动 system shell 执行浏览器二进制文件部署。
|
||||
"""
|
||||
try:
|
||||
logger.info("正在执行二进制文件:playwright install chromium")
|
||||
|
||||
Reference in New Issue
Block a user