|
60 | 60 | import importlib.abc |
61 | 61 | import inspect |
62 | 62 | import json |
63 | | -import logging |
64 | 63 | import os |
65 | 64 | import re |
66 | 65 | import shutil |
|
83 | 82 | plugin_capability_prefix, |
84 | 83 | validate_plugin_id, |
85 | 84 | ) |
| 85 | +from .._internal.sdk_logger import logger |
86 | 86 | from .._internal.typing_utils import unwrap_optional |
87 | 87 | from ..decorators import ( |
88 | 88 | ConversationMeta, |
|
119 | 119 | HandlerKind: TypeAlias = Literal["handler", "hook", "tool", "session"] |
120 | 120 | DiscoverySeverity: TypeAlias = Literal["warning", "error"] |
121 | 121 | DiscoveryPhase: TypeAlias = Literal["discovery", "load", "lifecycle", "reload"] |
122 | | -_LOGGER = logging.getLogger(__name__) |
123 | 122 | _PLUGIN_IMPORT_LOCK = threading.RLock() |
124 | 123 | _VALID_HANDLER_KINDS: tuple[HandlerKind, ...] = ("handler", "hook", "tool", "session") |
125 | 124 | _PLUGIN_PACKAGE_PREFIX = "astrbot_ext_" |
@@ -413,8 +412,8 @@ def _build_param_specs(handler: Any) -> list[ParamSpec]: |
413 | 412 | try: |
414 | 413 | type_hints = typing.get_type_hints(handler) |
415 | 414 | except Exception as exc: |
416 | | - _LOGGER.warning( |
417 | | - "Failed to resolve type hints for handler %s: %s", |
| 415 | + logger.warning( |
| 416 | + "Failed to resolve type hints for handler {}: {}", |
418 | 417 | getattr(handler, "__qualname__", repr(handler)), |
419 | 418 | exc, |
420 | 419 | ) |
@@ -648,22 +647,22 @@ def load_plugin_config_schema(plugin: PluginSpec) -> dict[str, Any]: |
648 | 647 | try: |
649 | 648 | schema_payload = json.loads(schema_path.read_text(encoding="utf-8")) |
650 | 649 | except json.JSONDecodeError as exc: |
651 | | - _LOGGER.warning( |
652 | | - "Failed to parse SDK plugin config schema %s: %s", |
| 650 | + logger.warning( |
| 651 | + "Failed to parse SDK plugin config schema {}: {}", |
653 | 652 | schema_path, |
654 | 653 | exc, |
655 | 654 | ) |
656 | 655 | return {} |
657 | 656 | except OSError as exc: |
658 | | - _LOGGER.warning( |
659 | | - "Failed to read SDK plugin config schema %s: %s", |
| 657 | + logger.warning( |
| 658 | + "Failed to read SDK plugin config schema {}: {}", |
660 | 659 | schema_path, |
661 | 660 | exc, |
662 | 661 | ) |
663 | 662 | return {} |
664 | 663 | if not isinstance(schema_payload, dict): |
665 | | - _LOGGER.warning( |
666 | | - "SDK plugin config schema %s must be a JSON object, got %s", |
| 664 | + logger.warning( |
| 665 | + "SDK plugin config schema {} must be a JSON object, got {}", |
667 | 666 | schema_path, |
668 | 667 | type(schema_payload).__name__, |
669 | 668 | ) |
@@ -716,15 +715,15 @@ def load_plugin_config( |
716 | 715 | else {} |
717 | 716 | ) |
718 | 717 | except json.JSONDecodeError as exc: |
719 | | - _LOGGER.warning( |
720 | | - "Failed to parse SDK plugin config %s: %s", |
| 718 | + logger.warning( |
| 719 | + "Failed to parse SDK plugin config {}: {}", |
721 | 720 | config_path, |
722 | 721 | exc, |
723 | 722 | ) |
724 | 723 | existing_payload = {} |
725 | 724 | except OSError as exc: |
726 | | - _LOGGER.warning( |
727 | | - "Failed to read SDK plugin config %s: %s", |
| 725 | + logger.warning( |
| 726 | + "Failed to read SDK plugin config {}: {}", |
728 | 727 | config_path, |
729 | 728 | exc, |
730 | 729 | ) |
@@ -1016,14 +1015,12 @@ def _load_state(state_path: Path) -> dict[str, Any]: |
1016 | 1015 | try: |
1017 | 1016 | data = json.loads(state_path.read_text(encoding="utf-8")) |
1018 | 1017 | except json.JSONDecodeError as exc: |
1019 | | - _LOGGER.warning( |
1020 | | - "Failed to parse plugin worker state %s: %s", state_path, exc |
| 1018 | + logger.warning( |
| 1019 | + "Failed to parse plugin worker state {}: {}", state_path, exc |
1021 | 1020 | ) |
1022 | 1021 | return {} |
1023 | 1022 | except OSError as exc: |
1024 | | - _LOGGER.warning( |
1025 | | - "Failed to read plugin worker state %s: %s", state_path, exc |
1026 | | - ) |
| 1023 | + logger.warning("Failed to read plugin worker state {}: {}", state_path, exc) |
1027 | 1024 | return {} |
1028 | 1025 | return data if isinstance(data, dict) else {} |
1029 | 1026 |
|
@@ -1114,8 +1111,8 @@ def _load_component_instance( |
1114 | 1111 | f"{_component_context(plugin, class_path=resolved_component.class_path, index=resolved_component.index)} " |
1115 | 1112 | f"实例化失败:{exc}" |
1116 | 1113 | ) from exc |
1117 | | - _LOGGER.debug( |
1118 | | - "Instantiated SDK plugin component %s for plugin %s", |
| 1114 | + logger.debug( |
| 1115 | + "Instantiated SDK plugin component {} for plugin {}", |
1119 | 1116 | resolved_component.class_path, |
1120 | 1117 | plugin.name, |
1121 | 1118 | ) |
@@ -1263,7 +1260,7 @@ def load_plugin(plugin: PluginSpec) -> LoadedPlugin: |
1263 | 1260 | 仅支持 v4 新版 Star 组件(无参构造函数)。 |
1264 | 1261 | """ |
1265 | 1262 | with _PLUGIN_IMPORT_LOCK: |
1266 | | - _LOGGER.debug("Loading SDK plugin %s from %s", plugin.name, plugin.plugin_dir) |
| 1263 | + logger.debug("Loading SDK plugin {} from {}", plugin.name, plugin.plugin_dir) |
1267 | 1264 | _ensure_plugin_import_hook_installed() |
1268 | 1265 | namespace = _register_plugin_import_namespace(plugin) |
1269 | 1266 | _purge_plugin_bytecode(plugin.plugin_dir) |
@@ -1304,8 +1301,8 @@ def load_plugin(plugin: PluginSpec) -> LoadedPlugin: |
1304 | 1301 | capabilities.extend(component_capabilities) |
1305 | 1302 | llm_tools.extend(component_tools) |
1306 | 1303 |
|
1307 | | - _LOGGER.debug( |
1308 | | - "Loaded SDK plugin %s: %d components, %d handlers, %d capabilities, %d llm tools, %d agents", |
| 1304 | + logger.debug( |
| 1305 | + "Loaded SDK plugin {}: {} components, {} handlers, {} capabilities, {} llm tools, {} agents", |
1309 | 1306 | plugin.name, |
1310 | 1307 | len(resolved_components), |
1311 | 1308 | len(handlers), |
|
0 commit comments