Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

involve kwargs to pass parameters on creating RichHandler for logging customization. (#1504)

itaru26223555ac96c0a5
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` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/utilities/logging.py#L22" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>
```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)