Feat/plugin log levels
Fixes #9186
Modifications / 改动点
- Added dedicated
astrbot.plugin.<plugin_name>loggers with independently configurable log levels. - Added persistent per-plugin log-level overrides supporting
DEBUG,INFO,WARNING,ERROR,CRITICAL, and “Follow Global”. - Updated
astrbot.api.loggerto automatically route logs to the calling plugin, including legacy plugins that do not callStar.__init__(). - Added
self.loggertoStarinstances and report the effective log level during plugin initialization. - Added Dashboard APIs, OpenAPI definitions, and generated frontend clients for reading and updating plugin log levels.
- Added an immediately applied log-level selector to the plugin configuration dialog, with localized UI text and success notifications.
- Improved configuration dialogs for plugins without additional configuration items.
- Added regression tests covering logger routing, plugin renaming/reloading, legacy plugin compatibility, API responses, and global-level synchronization.
- Updated plugin development documentation to describe dedicated plugin loggers and per-plugin log-level controls.
Backward Compatibility / 向后兼容性
-
Existing plugins using the historically recommended
from astrbot.api import loggerrequire no code changes. Their log calls are automatically routed to the dedicated plugin logger. -
Legacy plugins that do not call
super().__init__()remain supported and can still use per-plugin log-level controls throughastrbot.api.logger. -
Plugins using
self.loggercan opt into the dedicated logger directly. -
Existing global logging behavior remains unchanged for core code and callers using
from astrbot import logger. -
Plugins without an explicit log-level override continue to follow the global log level.
-
[x] This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
-
[x] 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc. / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
-
[x] 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above. / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
-
[x] 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in
requirements.txtandpyproject.toml. / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到requirements.txt和pyproject.toml文件相应位置。 -
[x] 😮 My changes do not introduce malicious code. / 我的更改没有引入恶意代码。
Summary by Sourcery
Add per-plugin logging configuration with dedicated loggers, dashboard controls, and supporting APIs while preserving backward-compatible behavior for existing plugins.
New Features:
- Introduce dedicated per-plugin loggers with independently configurable log levels and automatic routing from astrbot.api.logger.
- Add dashboard support for viewing and updating each plugins log level, including a log-level selector in the plugin configuration dialog.
Enhancements:
- Synchronize plugin logger levels with global logging when no per-plugin override is set, ensuring consistent behavior across core and plugins.
- Expose a self.logger attribute on Star instances and log each plugins effective level during initialization.
Documentation:
- Update plugin development documentation and OpenAPI specs to describe per-plugin log-level controls and the new log-level API.
Tests:
- Add regression tests covering plugin-aware logger routing, plugin renaming, legacy plugins that skip Star.init, global-level synchronization, and the new dashboard API responses.