> ## Documentation Index
> Fetch the complete documentation index at: https://enterprise-docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# プラグインのロギング

> SDK の plugin_logger_handler を使ってプラグインのログを出力します。リモートデバッグ中に確認でき、デーモンコンテナログにも記録されます

プラグインの開発やデバッグでは、コードの動作をログに記録したいことがよくあります。

プラグイン SDK は、Python の標準ライブラリ `logging` 用のハンドラを提供しています。これをロガーに追加すると、任意の文字列をリモートデバッグ中の標準出力とプラグインデーモンのコンテナログ（コミュニティ版のみ）の両方に出力できます。

## 例

`plugin_logger_handler` をインポートして、ロガーに追加します。以下の例は、ツールプラグインを示しています。

```python theme={null}
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!")
```

***

[このページを編集する](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)
