From 3555ac96c0a560a4a213bb8644030b35e7a1e668 Mon Sep 17 00:00:00 2001 From: itaru2622 <70509350+itaru2622@users.noreply.github.com> Date: Sat, 16 Aug 2025 00:37:17 +0900 Subject: [PATCH] involve kwargs to pass parameters on creating RichHandler for logging customization. (#1504) --- docs/python-sdk/fastmcp-utilities-logging.mdx | 3 ++- src/fastmcp/utilities/logging.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/python-sdk/fastmcp-utilities-logging.mdx b/docs/python-sdk/fastmcp-utilities-logging.mdx index f4eb26666..90564927c 100644 --- a/docs/python-sdk/fastmcp-utilities-logging.mdx +++ b/docs/python-sdk/fastmcp-utilities-logging.mdx @@ -29,7 +29,7 @@ Get a logger nested under FastMCP namespace. ### `configure_logging` ```python -configure_logging(level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | int = 'INFO', logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True) -> None +configure_logging(level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | int = 'INFO', logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True, **rich_kwargs: Any) -> None ``` @@ -38,4 +38,5 @@ Configure logging for FastMCP. **Args:** - `logger`: the logger to configure - `level`: the log level to use +- `rich_kwargs`: the parameters to use for creating RichHandler diff --git a/src/fastmcp/utilities/logging.py b/src/fastmcp/utilities/logging.py index 810be92d5..e27aa4600 100644 --- a/src/fastmcp/utilities/logging.py +++ b/src/fastmcp/utilities/logging.py @@ -1,7 +1,7 @@ """Logging utilities for FastMCP.""" import logging -from typing import Literal +from typing import Any, Literal from rich.console import Console from rich.logging import RichHandler @@ -23,6 +23,7 @@ def configure_logging( level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | int = "INFO", logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True, + **rich_kwargs: Any, ) -> None: """ Configure logging for FastMCP. @@ -30,6 +31,7 @@ def configure_logging( Args: logger: the logger to configure level: the log level to use + rich_kwargs: the parameters to use for creating RichHandler """ if logger is None: @@ -39,6 +41,7 @@ def configure_logging( handler = RichHandler( console=Console(stderr=True), rich_tracebacks=enable_rich_tracebacks, + **rich_kwargs, ) formatter = logging.Formatter("%(message)s") handler.setFormatter(formatter)