Skip to content

Conversation

@ocetars
Copy link
Member

@ocetars ocetars commented Jan 9, 2026

在报错日志前加入当前版本号信息,更易于 bug 问题定位

Modifications / 改动点

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

在警告和错误级别的控制台日志条目中附加当前 AstrBot 版本标签,以便更轻松地跟踪问题。

新功能:

  • 添加一个日志过滤器,将 AstrBot 版本标签注入到 WARN 和 ERROR 级别的日志记录中。
  • 扩展控制台日志格式,在日志级别信息旁显示 AstrBot 版本标签。
Original summary in English

Summary by Sourcery

Append the current AstrBot version tag to warning and error console log entries for easier issue tracing.

New Features:

  • Add a logging filter that injects the AstrBot version tag into WARN and ERROR level log records.
  • Extend the console log format to display the AstrBot version tag alongside log level information.

@auto-assign auto-assign bot requested review from Raven95676 and anka-afk January 9, 2026 10:05
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 9, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我发现了 1 个问题,并给出了一些整体性的反馈:

  • 在模块级别从 astrbot.core.config.default 导入 VERSION,如果该模块在初始化时使用了 logging,则有产生循环导入问题的风险;建议在过滤器内部延迟获取版本信息,或者通过一个小的辅助函数来处理,以解耦 logging 与配置导入顺序。
  • 条件 if record.levelno == logging.WARNING or record.levelno >= logging.ERROR 在逻辑上等价于 record.levelno >= logging.WARNING;简化这一条件可以让意图更清晰并减少重复。
  • 注释和 docstring 中提到的是 WARN/ERRO,但标准的 logging 级别字符串是 WARNING/ERROR;统一用语可以避免之后的读者产生困惑。
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Importing `VERSION` at module level from `astrbot.core.config.default` risks circular import issues if that module uses logging during initialization; consider resolving the version lazily inside the filter or via a small helper function to decouple logging from configuration import order.
- The condition `if record.levelno == logging.WARNING or record.levelno >= logging.ERROR` is equivalent to `record.levelno >= logging.WARNING`; simplifying this will make the intent clearer and reduce duplication.
- The comment and docstring mention `WARN/ERRO` but the standard logging level strings are `WARNING/ERROR`; aligning the wording will avoid confusion for future readers.

## Individual Comments

### Comment 1
<location> `astrbot/core/log.py:242` </location>
<code_context>
         logger.addFilter(PluginFilter())  # 添加插件过滤器
         logger.addFilter(FileNameFilter())  # 添加文件名过滤器
         logger.addFilter(LevelNameFilter())  # 添加级别名称过滤器
+        logger.addFilter(AstrBotVersionTagFilter())  # 追加版本号(仅 WARN/ERRO)
         logger.setLevel(logging.DEBUG)  # 设置日志级别为DEBUG
         logger.addHandler(console_handler)  # 添加处理器到logger
</code_context>

<issue_to_address>
**nitpick (typo):** Fix minor typo and keep wording consistent with actual behavior.

The comment says `WARN/ERRO` and implies the tag is only for WARN/ERROR, but with `== WARNING or >= ERROR`, CRITICAL and above also get the tag. Please fix the typo (`ERRO` -> `ERROR`) and rephrase the comment (e.g., `WARN 及以上`) to match the actual behavior.

```suggestion
        logger.addFilter(AstrBotVersionTagFilter())  # 追加版本号(仅 WARN 及以上)
```
</issue_to_address>

Sourcery 对开源项目是免费的——如果你觉得这次评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've found 1 issue, and left some high level feedback:

  • Importing VERSION at module level from astrbot.core.config.default risks circular import issues if that module uses logging during initialization; consider resolving the version lazily inside the filter or via a small helper function to decouple logging from configuration import order.
  • The condition if record.levelno == logging.WARNING or record.levelno >= logging.ERROR is equivalent to record.levelno >= logging.WARNING; simplifying this will make the intent clearer and reduce duplication.
  • The comment and docstring mention WARN/ERRO but the standard logging level strings are WARNING/ERROR; aligning the wording will avoid confusion for future readers.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Importing `VERSION` at module level from `astrbot.core.config.default` risks circular import issues if that module uses logging during initialization; consider resolving the version lazily inside the filter or via a small helper function to decouple logging from configuration import order.
- The condition `if record.levelno == logging.WARNING or record.levelno >= logging.ERROR` is equivalent to `record.levelno >= logging.WARNING`; simplifying this will make the intent clearer and reduce duplication.
- The comment and docstring mention `WARN/ERRO` but the standard logging level strings are `WARNING/ERROR`; aligning the wording will avoid confusion for future readers.

## Individual Comments

### Comment 1
<location> `astrbot/core/log.py:242` </location>
<code_context>
         logger.addFilter(PluginFilter())  # 添加插件过滤器
         logger.addFilter(FileNameFilter())  # 添加文件名过滤器
         logger.addFilter(LevelNameFilter())  # 添加级别名称过滤器
+        logger.addFilter(AstrBotVersionTagFilter())  # 追加版本号(仅 WARN/ERRO)
         logger.setLevel(logging.DEBUG)  # 设置日志级别为DEBUG
         logger.addHandler(console_handler)  # 添加处理器到logger
</code_context>

<issue_to_address>
**nitpick (typo):** Fix minor typo and keep wording consistent with actual behavior.

The comment says `WARN/ERRO` and implies the tag is only for WARN/ERROR, but with `== WARNING or >= ERROR`, CRITICAL and above also get the tag. Please fix the typo (`ERRO` -> `ERROR`) and rephrase the comment (e.g., `WARN 及以上`) to match the actual behavior.

```suggestion
        logger.addFilter(AstrBotVersionTagFilter())  # 追加版本号(仅 WARN 及以上)
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

logger.addFilter(PluginFilter()) # 添加插件过滤器
logger.addFilter(FileNameFilter()) # 添加文件名过滤器
logger.addFilter(LevelNameFilter()) # 添加级别名称过滤器
logger.addFilter(AstrBotVersionTagFilter()) # 追加版本号(仅 WARN/ERRO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): 修正一个小拼写错误,并让措辞与实际行为保持一致。

当前注释写的是 WARN/ERRO,并且暗示只有 WARN/ERROR 级别才会带上这个标签,但在 == WARNING or >= ERROR 这个条件下,CRITICAL 及以上级别也会带上标签。请修正拼写错误(ERRO -> ERROR),并重新表述注释(例如改为 WARN 及以上),以更准确地反映实际行为。

Suggested change
logger.addFilter(AstrBotVersionTagFilter()) # 追加版本号(仅 WARN/ERRO
logger.addFilter(AstrBotVersionTagFilter()) # 追加版本号(仅 WARN 及以上
Original comment in English

nitpick (typo): Fix minor typo and keep wording consistent with actual behavior.

The comment says WARN/ERRO and implies the tag is only for WARN/ERROR, but with == WARNING or >= ERROR, CRITICAL and above also get the tag. Please fix the typo (ERRO -> ERROR) and rephrase the comment (e.g., WARN 及以上) to match the actual behavior.

Suggested change
logger.addFilter(AstrBotVersionTagFilter()) # 追加版本号(仅 WARN/ERRO
logger.addFilter(AstrBotVersionTagFilter()) # 追加版本号(仅 WARN 及以上

@dosubot dosubot bot added the area:core The bug / feature is about astrbot's core, backend label Jan 9, 2026
"""在 WARN/ERRO 日志后追加当前 AstrBot 版本号。"""

def filter(self, record):
if record.levelno == logging.WARNING or record.levelno >= logging.ERROR:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

等价于 record.levelno >= logging.WARNING ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants