Skip to content

Commit 70be590

Browse files
committed
完善文档
1 parent 9e7f92e commit 70be590

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

docs/en/dev/plugin-platform-adapter.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ class FakePlatformAdapter(Platform):
8585

8686
# FakeClient 是我们自己定义的,这里只是示例。这个是其回调函数
8787
async def on_received(data):
88-
logger.info(data)
88+
logger.info(
89+
"Received platform message: %s",
90+
data,
91+
extra={"tag": "platform:fake", "platform_id": "fake"},
92+
)
8993
abm = await self.convert_message(data=data) # 转换成 AstrBotMessage
9094
await self.handle_msg(abm)
9195

@@ -122,6 +126,10 @@ class FakePlatformAdapter(Platform):
122126
self.commit_event(message_event) # 提交事件到事件队列。不要忘记!
123127
```
124128

129+
> [!TIP]
130+
>
131+
> The new console supports filtering by fields such as `tag`, `platform_id`, and `umo`. For platform adapters, it is recommended to attach at least a stable `tag` to important logs, for example `extra={"tag": "platform:fake", "platform_id": "fake"}`, so WebUI troubleshooting stays straightforward.
132+
125133

126134
`fake_platform_event.py`
127135

@@ -182,4 +190,4 @@ class MyPlugin(Star):
182190
![image](https://files.astrbot.app/docs/source/images/plugin-platform-adapter/QQ_1738156166893.png)
183191

184192

185-
有任何疑问欢迎加群询问~
193+
有任何疑问欢迎加群询问~

docs/en/dev/star/guides/simple.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MyPlugin(Star):
1717
'''This is a hello world command''' # This is the handler's description, which will be parsed to help users understand the plugin's functionality. Highly recommended to provide.
1818
user_name = event.get_sender_name()
1919
message_str = event.message_str # Get the plain text content of the message
20-
logger.info("Hello world command triggered!")
20+
logger.info("Hello world command triggered!", extra={"tag": "plugin:my_plugin"})
2121
yield event.plain_result(f"Hello, {user_name}!") # Send a plain text message
2222

2323
async def terminate(self):
@@ -37,6 +37,8 @@ Explanation:
3737
> Handlers must be registered within the plugin class, with the first two parameters being `self` and `event`. If the file becomes too long, you can write services externally and call them from the handler.
3838
>
3939
> The file containing the plugin class must be named `main.py`.
40+
>
41+
> The new console supports filtering by `tag`. For plugin development, it is recommended to add `extra={"tag": "plugin:your_plugin"}` to important logs. If you need more dimensions, you can also provide fields such as `tags`, `platform_id`, `plugin_name`, and `umo`.
4042
4143
All handler functions must be written within the plugin class. To keep content concise, in subsequent sections, we may omit the plugin class definition.
4244
```

docs/zh/dev/plugin-platform-adapter.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ class FakePlatformAdapter(Platform):
8585

8686
# FakeClient 是我们自己定义的,这里只是示例。这个是其回调函数
8787
async def on_received(data):
88-
logger.info(data)
88+
logger.info(
89+
"收到平台消息: %s",
90+
data,
91+
extra={"tag": "platform:fake", "platform_id": "fake"},
92+
)
8993
abm = await self.convert_message(data=data) # 转换成 AstrBotMessage
9094
await self.handle_msg(abm)
9195

@@ -122,6 +126,10 @@ class FakePlatformAdapter(Platform):
122126
self.commit_event(message_event) # 提交事件到事件队列。不要忘记!
123127
```
124128

129+
> [!TIP]
130+
>
131+
> 新版日志控制台支持按 `tag``platform_id``umo` 等字段筛选。平台适配器建议至少为关键日志带上稳定的 `tag`,例如 `extra={"tag": "platform:fake", "platform_id": "fake"}`,这样在 WebUI 中排查问题会更直接。
132+
125133

126134
`fake_platform_event.py`
127135

@@ -182,4 +190,4 @@ class MyPlugin(Star):
182190
![image](https://files.astrbot.app/docs/source/images/plugin-platform-adapter/QQ_1738156166893.png)
183191

184192

185-
有任何疑问欢迎加群询问~
193+
有任何疑问欢迎加群询问~

docs/zh/dev/star/guides/simple.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class MyPlugin(Star):
1717
'''这是一个 hello world 指令''' # 这是 handler 的描述,将会被解析方便用户了解插件内容。非常建议填写。
1818
user_name = event.get_sender_name()
1919
message_str = event.message_str # 获取消息的纯文本内容
20-
logger.info("触发hello world指令!")
20+
logger.info("触发hello world指令!", extra={"tag": "plugin:my_plugin"})
2121
yield event.plain_result(f"Hello, {user_name}!") # 发送一条纯文本消息
2222

2323
async def terminate(self):
@@ -37,5 +37,7 @@ class MyPlugin(Star):
3737
> `Handler` 一定需要在插件类中注册,前两个参数必须为 `self``event`。如果文件行数过长,可以将服务写在外部,然后在 `Handler` 中调用。
3838
>
3939
> 插件类所在的文件名需要命名为 `main.py`
40+
>
41+
> 新版日志控制台支持按 `tag` 筛选。开发插件时,建议为关键日志补充 `extra={"tag": "plugin:your_plugin"}`;如果需要更细的筛选维度,也可以额外传入 `tags``platform_id``plugin_name``umo` 等字段。
4042
4143
所有的处理函数都需写在插件类中。为了精简内容,在之后的章节中,我们可能会忽略插件类的定义。

0 commit comments

Comments
 (0)