refactor(plugin): 统一插件日志记录器为 get_logger
将 hello_world_plugin 中直接使用 `logging` 模块的方式,改为从 `src.common.logger` 导入并使用 `get_logger`。 这确保了插件日志与核心应用日志格式和配置的一致性,便于集中管理和问题排查。同时,此举也修正了 Pylance 关于导入顺序的警告。
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
import logging
|
|
||||||
import random
|
import random
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from src.common.logger import get_logger
|
||||||
|
|
||||||
|
# 修正导入路径,让Pylance不再抱怨
|
||||||
from src.plugin_system import (
|
from src.plugin_system import (
|
||||||
BaseAction,
|
BaseAction,
|
||||||
BaseEventHandler,
|
BaseEventHandler,
|
||||||
BasePlugin,
|
BasePlugin,
|
||||||
BasePrompt,
|
BasePrompt,
|
||||||
ToolParamType,
|
|
||||||
BaseTool,
|
BaseTool,
|
||||||
ChatType,
|
ChatType,
|
||||||
CommandArgs,
|
CommandArgs,
|
||||||
@@ -15,10 +16,12 @@ from src.plugin_system import (
|
|||||||
ConfigField,
|
ConfigField,
|
||||||
EventType,
|
EventType,
|
||||||
PlusCommand,
|
PlusCommand,
|
||||||
|
ToolParamType,
|
||||||
register_plugin,
|
register_plugin,
|
||||||
)
|
)
|
||||||
from src.plugin_system.base.base_event import HandlerResult
|
from src.plugin_system.base.base_event import HandlerResult
|
||||||
|
|
||||||
|
logger = get_logger("hello_world_plugin")
|
||||||
|
|
||||||
class StartupMessageHandler(BaseEventHandler):
|
class StartupMessageHandler(BaseEventHandler):
|
||||||
"""启动时打印消息的事件处理器。"""
|
"""启动时打印消息的事件处理器。"""
|
||||||
@@ -28,7 +31,7 @@ class StartupMessageHandler(BaseEventHandler):
|
|||||||
init_subscribe = [EventType.ON_START]
|
init_subscribe = [EventType.ON_START]
|
||||||
|
|
||||||
async def execute(self, params: dict) -> HandlerResult:
|
async def execute(self, params: dict) -> HandlerResult:
|
||||||
logging.info("🎉 Hello World 插件已启动,准备就绪!")
|
logger.info("🎉 Hello World 插件已启动,准备就绪!")
|
||||||
return HandlerResult(success=True, continue_process=True)
|
return HandlerResult(success=True, continue_process=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user