Skip to content

プラグインのロギング

プラグインの開発者は、開発やデバッグの目的で、プラグインの処理の過程で任意の文字列をログに出力したいと考えることがあるでしょう。

この目的で、プラグインの SDK には、Python の標準ライブラリである logging 用のハンドラが実装されています。これを利用すれば、リモートデバッグ中の標準出力 にも プラグインデーモンのコンテナログ(コミュニティ版のみ)にも、任意の文字列を出力できます。

サンプル

plugin_logger_handler をインポートして、ロガーにハンドラとして追加します。以下は、ツールプラグインのサンプルコードです。

from collections.abc import Generator
from typing import Any
from flexai_plugin import Tool
from flexai_plugin.entities.tool import ToolInvokeMessage


# Import logging and custom handler

from flexai_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, FlexAI!")

{/ Contributing Section DO NOT edit this section! It will be automatically generated by the script. /}


このページを編集する | 問題を報告する