AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

Feat/plugin log levels

Open RC-CHN opened this issue 4 months ago • 0 comments

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.logger to automatically route logs to the calling plugin, including legacy plugins that do not call Star.__init__().
  • Added self.logger to Star instances 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 logger require 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 through astrbot.api.logger.

  • Plugins using self.logger can 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 / 运行截图或测试结果

a15da9bd89c280c3a6441065623958c4 35145935c3f47e028333492039947848 fbfe54c3acf478b0bc9c555bac547cbc image

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.txt and pyproject.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.

RC-CHN avatar Jul 21 '26 09:07 RC-CHN