mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-23 04:09:59 +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()
|
||||
|
||||
Reference in New Issue
Block a user