> ## 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` 提供了一个处理器。将它添加到 logger 后，任意字符串都会同时输出到远程调试时的标准输出和插件守护进程的容器日志（仅 Community Edition）。

## 示例

导入 `plugin_logger_handler` 并将其添加到 logger。以下示例展示了一个工具插件。

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