Skip to content

feat: 为平台日志增加剔除用户对话功能#9165

Open
M1LKT wants to merge 3 commits into
AstrBotDevs:masterfrom
M1LKT:feat/#9011
Open

feat: 为平台日志增加剔除用户对话功能#9165
M1LKT wants to merge 3 commits into
AstrBotDevs:masterfrom
M1LKT:feat/#9011

Conversation

@M1LKT

@M1LKT M1LKT commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Modifications / 改动点

平台日志新增「排除用户对话」开关,方便排查插件/调用类 bug

为 WebUI 「平台日志」页面新增一个开关,开启后过滤掉冲屏的用户收发消息日志,只保留插件调用、Provider 调用、pipeline 调度、异常堆栈等系统侧日志,便于快速定位 bug。

功能简介:

  • 在「平台日志」页面右上角自动滚动开关旁并排新增「排除用户对话」v-switch
  • 状态持久化到 localStorageconsole_hide_user_chat),刷新后恢复
  • 与已有日志级别 chip(DEBUG / INFO / WARN / ERRO / CRIT)可叠加使用
  • 后端给每条日志打 category 标签,默认 system;用户收发消息日志标 user_chat
  • 历史日志缓存中无 category 字段的老条目按 system 处理,不会被误隐藏,向后兼容
  • 与 SSE 断线重连、日志级别筛选组合时行为正确

改动文件:

  1. astrbot/core/log.py

    • _RecordEnricherFilter.filter()LogRecord 注入默认 record.category = "system"
    • _patch_record() 在 loguru extra 中设默认 categorysystem,保持对称
    • LogQueueHandler.emit() 在发布到 LogBroker 的字典中新增 category 字段
  2. astrbot/core/event_bus.py

    • _print_event() 两处 logger.info(...) 增加 extra={"category": "user_chat"},标记收到用户消息的日志
  3. astrbot/core/pipeline/respond/stage.py

    • 发送回复处的 logger.info(f"Prepare to send - ...") 增加 extra={"category": "user_chat"},标记回复用户消息的日志
    • 同文件其它日志(调度/异常)不动,天然归入 system
  4. dashboard/src/components/shared/ConsoleDisplayer.vue

    • 新增 prop hideUserChat: Boolean(默认 false
    • 新增方法 isHiddenByCategory(log):当 hideUserChat && log.category === 'user_chat' 时返回 true
    • processNewLogs()refreshDisplay() 中在已有级别筛选基础上复合 && !this.isHiddenByCategory(log)
    • 新增对 hideUserChat prop 的 watcher,变化时调用 refreshDisplay()
  5. dashboard/src/views/ConsolePage.vue

    • data() 新增 hideUserChatEnabled,从 localStorage('console_hide_user_chat') 初始化
    • header 右侧 auto-scroll 开关前并排新增一个「排除用户对话」v-switch
    • watch.hideUserChatEnabled 写 localStorage
    • <ConsoleDisplayer> 新增 :hide-user-chat="hideUserChatEnabled" 单向 prop 绑定
  6. dashboard/src/i18n/locales/{zh-CN,en-US,ru-RU}/features/console.json

    • 新增 hideUserChat.enabled / hideUserChat.disabled 文案
  • This is NOT a breaking change. / 这不是一个破坏性变更。

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

验证步骤:

  1. 重启后端与前端 dev server,进入 WebUI「平台日志」页面
  2. 确认右上角自动滚动开关旁出现「排除用户对话」开关,状态为关闭
  3. 触发若干用户消息,确认默认(开关关闭)时所有日志(含 [平台] xxx/xxx: ... 收消息行、Prepare to send - ... 回复行、插件 handler / Provider / stage 调度日志)均显示
  4. 打开「排除用户对话」开关,确认:
    • [平台] xxx/xxx: ... 收消息行被隐藏
    • Prepare to send - xxx/xxx: ... 回复行被隐藏
    • 插件 handler / Provider / pipeline stage 的 INFO 日志仍显示
  5. 同时组合「排除用户对话」开关与日志级别 chip(如只勾选 ERROR),确认两类过滤叠加正确
  6. 刷新页面:开关状态从 localStorage 恢复,历史日志缓存中无 category 字段的老条目不被误隐藏

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了"验证步骤"和"运行截图"

  • 🤓 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.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

Summary by Sourcery

Add categorization to platform logs and a UI toggle to hide user chat entries from the console view.

New Features:

  • Introduce a "Exclude user conversation" switch on the platform log web UI to filter out user chat logs while retaining system-side logs.

Enhancements:

  • Tag backend log records with a category field (system vs user_chat) and propagate it through the log queue for more flexible frontend filtering.
  • Persist the "Exclude user conversation" switch state in localStorage and integrate it with existing log level filtering and auto-scroll behavior.
  • Extend console i18n resources with labels for the new "Exclude user conversation" switch in supported locales.

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. area:webui The bug / feature is about webui(dashboard) of astrbot. labels Jul 6, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a feature to filter out user chat logs from the console display. It tags user chat logs with a category extra field in the backend, and adds a toggle switch in the frontend console page to hide these logs, persisting the setting in local storage. The review feedback suggests handling cases where category might be explicitly set to None or an empty string in the logging backend, using optional chaining to simplify null checks in the frontend, and adding the missing Russian translation file that was omitted from the changes.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +7 to +10
"hideUserChat": {
"enabled": "User chat hidden",
"disabled": "Hide user chat"
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

在 PR 说明中提到了修改 dashboard/src/i18n/locales/{zh-CN,en-US,ru-RU}/features/console.json,但实际提交的文件中缺少了 ru-RU 的翻译文件。如果项目支持俄语,请确保也将 ru-RU 的翻译补上,以避免在俄语环境下出现文案缺失或显示键名的问题。

Comment thread astrbot/core/log.py Outdated
Comment thread astrbot/core/log.py Outdated
Comment on lines +255 to +257
isHiddenByCategory(log) {
return this.hideUserChat && log && log.category === 'user_chat';
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

可以使用可选链(Optional Chaining)来简化 log 的空值判断,使代码更加简洁和现代。

    isHiddenByCategory(log) {
      return this.hideUserChat && log?.category === 'user_chat';
    },

M1LKT and others added 2 commits July 7, 2026 08:13
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:webui The bug / feature is about webui(dashboard) of astrbot. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant