Skip to main content
このドキュメントは AI によって自動翻訳されています。不正確な部分がある場合は、英語版 を参照してください。
プラグインの開発やデバッグでは、コードの動作をログに記録したいことがよくあります。 プラグイン SDK は、Python の標準ライブラリ logging 用のハンドラを提供しています。これをロガーに追加すると、任意の文字列をリモートデバッグ中の標準出力とプラグインデーモンのコンテナログ(Community Edition のみ)の両方に出力できます。

plugin_logger_handler をインポートして、ロガーに追加します。以下の例は、ツールプラグインを示しています。
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!")
Last modified on June 25, 2026