> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-new-agent-experience.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# プラグインのロギング

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

> このドキュメントは AI によって自動翻訳されています。不正確な部分がある場合は、[英語版](/en/develop-plugin/features-and-specs/plugin-types/plugin-logging) を参照してください。

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

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

## 例

`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!")
```
