add missing plugin logging (#593)

* add missing plugin logging

* Update en/develop-plugin/features-and-specs/plugin-types/plugin-logs.mdx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update en/develop-plugin/features-and-specs/plugin-types/plugin-logs.mdx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update en/develop-plugin/features-and-specs/plugin-types/plugin-logs.mdx

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* modify the file name to make it consistent with the doc title

* add zh and jp docs

* Fix log message severity level typos

* Fix typos

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Riskey <riskey47@dify.ai>
Co-authored-by: Riskey <36894937+RiskeyL@users.noreply.github.com>
This commit is contained in:
非法操作
2025-12-12 12:23:29 +08:00
committed by GitHub
parent 4bab66539c
commit 6669cce727
4 changed files with 155 additions and 3 deletions

View File

@@ -321,7 +321,8 @@
"en/develop-plugin/features-and-specs/plugin-types/tool",
"en/develop-plugin/features-and-specs/plugin-types/plugin-info-by-manifest",
"en/develop-plugin/features-and-specs/plugin-types/multilingual-readme",
"en/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin"
"en/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin",
"en/develop-plugin/features-and-specs/plugin-types/plugin-logging"
]
},
{
@@ -696,7 +697,8 @@
"zh/develop-plugin/features-and-specs/plugin-types/tool",
"zh/develop-plugin/features-and-specs/plugin-types/plugin-info-by-manifest",
"zh/develop-plugin/features-and-specs/plugin-types/multilingual-readme",
"zh/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin"
"zh/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin",
"zh/develop-plugin/features-and-specs/plugin-types/plugin-logging"
]
},
{
@@ -1069,7 +1071,8 @@
"ja/develop-plugin/features-and-specs/plugin-types/tool",
"ja/develop-plugin/features-and-specs/plugin-types/plugin-info-by-manifest",
"ja/develop-plugin/features-and-specs/plugin-types/multilingual-readme",
"ja/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin"
"ja/develop-plugin/features-and-specs/plugin-types/remote-debug-a-plugin",
"ja/develop-plugin/features-and-specs/plugin-types/plugin-logging"
]
},
{

View File

@@ -0,0 +1,50 @@
---
title: Plugin Logging
---
As a plugin developer, you may want to print arbitrary strings to logs during plugin processing for development or debugging purposes.
For this purpose, the plugin SDK implements a handler for Python's standard `logging` library. By using this, you can output any string to both the **standard output during remote debugging** and the **plugin daemon container logs** (community edition only).
## Sample
Import `plugin_logger_handler` and add it to your logger as a handler. Below is a sample code for a tool plugin.
```python
from collections.abc import Generator
from typing import Any
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage
# Import logging and custom handler
import logging
from dify_plugin.config.logger_format import plugin_logger_handler
# Set up logging with the custom handler
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(plugin_logger_handler)
class LoggerDemoTool(Tool):
def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
# Log messages with different severity levels
logger.info("This is an INFO log message.")
logger.warning("This is a WARNING log message.")
logger.error("This is an ERROR log message.")
yield self.create_text_message("Hello, Dify!")
```
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[Edit this page](https://github.com/langgenius/dify-docs/edit/main/en/develop-plugin/features-and-specs/plugin-types/plugin-logging.mdx) | [Report an issue](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)

View File

@@ -0,0 +1,49 @@
---
title: プラグインのロギング
---
プラグインの開発者は、開発やデバッグの目的で、プラグインの処理の過程で任意の文字列をログに出力したいと考えることがあるでしょう。
この目的で、プラグインの SDK には、Python の標準ライブラリである `logging` 用のハンドラが実装されています。これを利用すれば、**リモートデバッグ中の標準出力** にも **プラグインデーモンのコンテナログ**(コミュニティ版のみ)にも、任意の文字列を出力できます。
## サンプル
`plugin_logger_handler` をインポートして、ロガーにハンドラとして追加します。以下は、ツールプラグインのサンプルコードです。
```python
from collections.abc import Generator
from typing import Any
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage
# Import logging and custom handler
import logging
from dify_plugin.config.logger_format import plugin_logger_handler
# Set up logging with the custom handler
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(plugin_logger_handler)
class LoggerDemoTool(Tool):
def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
# Log messages with different severity levels
logger.info("This is an INFO log message.")
logger.warning("This is a WARNING log message.")
logger.error("This is an ERROR log message.")
yield self.create_text_message("Hello, Dify!")
```
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[このページを編集する](https://github.com/langgenius/dify-docs/edit/main/ja/develop-plugin/features-and-specs/plugin-types/plugin-logging.mdx) | [問題を報告する](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)

View File

@@ -0,0 +1,50 @@
---
title: 输出插件日志
---
作为插件开发者,你可能希望在插件处理过程中,为了开发或调试目的,将任意字符串输出到日志中。
为此,插件 SDK 实现了一个适用于 Python 标准库 `logging` 的处理器。通过使用它,你可以将任意字符串输出到**远程调试时的标准输出**以及**插件守护进程的容器日志**(仅社区版)。
## 示例
导入 `plugin_logger_handler` 并将其添加到你的 logger 处理器中。以下是工具插件的示例代码。
```python
from collections.abc import Generator
from typing import Any
from dify_plugin import Tool
from dify_plugin.entities.tool import ToolInvokeMessage
# 导入 logging 和自定义处理器
import logging
from dify_plugin.config.logger_format import plugin_logger_handler
# 使用自定义处理器设置日志
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(plugin_logger_handler)
class LoggerDemoTool(Tool):
def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessage]:
# 以不同级别输出日志信息
logger.info("This is an INFO log message.")
logger.warning("This is a WARNING log message.")
logger.error("This is an ERROR log message.")
yield self.create_text_message("Hello, Dify!")
```
{/*
Contributing Section
DO NOT edit this section!
It will be automatically generated by the script.
*/}
---
[编辑此页面](https://github.com/langgenius/dify-docs/edit/main/zh/develop-plugin/features-and-specs/plugin-types/plugin-logging.mdx) | [提交问题](https://github.com/langgenius/dify-docs/issues/new?template=docs.yml)