Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions astrbot/core/event_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ def _print_event(self, event: AstrMessageEvent, conf_name: str) -> None:
if event.get_sender_name():
logger.info(
f"[{conf_name}] [{event.get_platform_id()}({event.get_platform_name()})] {event.get_sender_name()}/{event.get_sender_id()}: {event.get_message_outline()}",
extra={"category": "user_chat"},
)
# 没有发送者名称: [平台名] 发送者ID: 消息概要
else:
logger.info(
f"[{conf_name}] [{event.get_platform_id()}({event.get_platform_name()})] {event.get_sender_id()}: {event.get_message_outline()}",
extra={"category": "user_chat"},
)
3 changes: 3 additions & 0 deletions astrbot/core/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def filter(self, record: logging.LogRecord) -> bool:
record.source_file = _build_source_file(record.pathname)
record.source_line = record.lineno
record.is_trace = record.name == "astrbot.trace"
record.category = getattr(record, "category", None) or "system"
return True


Expand Down Expand Up @@ -88,6 +89,7 @@ def _patch_record(record: "Record") -> None:
extra.setdefault("source_file", _build_source_file(record["file"].path))
extra.setdefault("source_line", record["line"])
extra.setdefault("is_trace", False)
extra.setdefault("category", "system")


_loguru = _raw_loguru_logger.patch(_patch_record)
Expand Down Expand Up @@ -161,6 +163,7 @@ def emit(self, record: logging.LogRecord) -> None:
"level": record.levelname,
"time": time.time(),
"data": log_entry,
"category": getattr(record, "category", None) or "system",
},
)

Expand Down
1 change: 1 addition & 0 deletions astrbot/core/pipeline/respond/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ async def process(

logger.info(
f"Prepare to send - {event.get_sender_name()}/{event.get_sender_id()}: {event._outline_chain(result.chain)}",
extra={"category": "user_chat"},
)

if result.result_content_type == ResultContentType.STREAMING_RESULT:
Expand Down
17 changes: 14 additions & 3 deletions dashboard/src/components/shared/ConsoleDisplayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export default {
showLevelBtns: {
type: Boolean,
default: true
},
hideUserChat: {
type: Boolean,
default: false
}
},
watch: {
Expand All @@ -84,6 +88,9 @@ export default {
this.refreshDisplay();
},
deep: true
},
hideUserChat() {
this.refreshDisplay();
}
},
async mounted() {
Expand Down Expand Up @@ -203,8 +210,8 @@ export default {
if (!exists) {
this.localLogCache.push(log);
hasUpdate = true;
if (this.isLevelSelected(log.level)) {

if (this.isLevelSelected(log.level) && !this.isHiddenByCategory(log)) {
this.printLog(log.data);
}
}
Expand Down Expand Up @@ -245,14 +252,18 @@ export default {
return false;
},

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

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';
    },


refreshDisplay() {
const termElement = document.getElementById('term');
if (termElement) {
termElement.innerHTML = '';

if (this.localLogCache && this.localLogCache.length > 0) {
this.localLogCache.forEach(logItem => {
if (this.isLevelSelected(logItem.level)) {
if (this.isLevelSelected(logItem.level) && !this.isHiddenByCategory(logItem)) {
this.printLog(logItem.data);
}
});
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/i18n/locales/en-US/features/console.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"enabled": "Auto-scroll enabled",
"disabled": "Auto-scroll disabled"
},
"hideUserChat": {
"enabled": "User chat hidden",
"disabled": "Hide user chat"
},
Comment on lines +7 to +10

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 的翻译补上,以避免在俄语环境下出现文案缺失或显示键名的问题。

"pipInstall": {
"button": "Install pip Package",
"dialogTitle": "Install Pip Package",
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/i18n/locales/zh-CN/features/console.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"enabled": "自动滚动已开启",
"disabled": "自动滚动已关闭"
},
"hideUserChat": {
"enabled": "已排除用户对话",
"disabled": "排除用户对话"
},
"pipInstall": {
"button": "安装 pip 库",
"dialogTitle": "安装 Pip 库",
Expand Down
15 changes: 14 additions & 1 deletion dashboard/src/views/ConsolePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ const { tm } = useModuleI18n('features/console');
</p>
</div>
<div class="d-flex align-center">
<v-switch
v-model="hideUserChatEnabled"
:label="hideUserChatEnabled ? tm('hideUserChat.enabled') : tm('hideUserChat.disabled')"
hide-details
density="compact"
inset
color="primary"
style="margin-right: 16px;"
></v-switch>
<v-switch
v-model="autoScrollEnabled"
:label="autoScrollEnabled ? tm('autoScroll.enabled') : tm('autoScroll.disabled')"
Expand Down Expand Up @@ -49,7 +58,7 @@ const { tm } = useModuleI18n('features/console');
</v-dialog>
</div>
</div>
<ConsoleDisplayer ref="consoleDisplayer" class="console-display" />
<ConsoleDisplayer ref="consoleDisplayer" class="console-display" :hide-user-chat="hideUserChatEnabled" />
</div>
</template>
<script>
Expand All @@ -61,6 +70,7 @@ export default {
data() {
return {
autoScrollEnabled: localStorage.getItem('console_auto_scroll') !== 'false',
hideUserChatEnabled: localStorage.getItem('console_hide_user_chat') === 'true',
pipDialog: false,
pipInstallPayload: {
package: '',
Expand All @@ -80,6 +90,9 @@ export default {
if (this.$refs.consoleDisplayer) {
this.$refs.consoleDisplayer.autoScroll = val;
}
},
hideUserChatEnabled(val) {
localStorage.setItem('console_hide_user_chat', val);
}
},
methods: {
Expand Down
Loading