Spaces:
Running
Running
itaru2622 commited on
involve kwargs to pass parameters on creating RichHandler for logging customization. (#1504)
Browse files
docs/python-sdk/fastmcp-utilities-logging.mdx
CHANGED
|
@@ -29,7 +29,7 @@ Get a logger nested under FastMCP namespace.
|
|
| 29 |
### `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>
|
| 30 |
|
| 31 |
```python
|
| 32 |
-
configure_logging(level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | int = 'INFO', logger: logging.Logger | None = None, enable_rich_tracebacks: bool = True) -> None
|
| 33 |
```
|
| 34 |
|
| 35 |
|
|
@@ -38,4 +38,5 @@ Configure logging for FastMCP.
|
|
| 38 |
**Args:**
|
| 39 |
- `logger`: the logger to configure
|
| 40 |
- `level`: the log level to use
|
|
|
|
| 41 |
|
|
|
|
| 29 |
### `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>
|
| 30 |
|
| 31 |
```python
|
| 32 |
+
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
|
| 33 |
```
|
| 34 |
|
| 35 |
|
|
|
|
| 38 |
**Args:**
|
| 39 |
- `logger`: the logger to configure
|
| 40 |
- `level`: the log level to use
|
| 41 |
+
- `rich_kwargs`: the parameters to use for creating RichHandler
|
| 42 |
|
src/fastmcp/utilities/logging.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
"""Logging utilities for FastMCP."""
|
| 2 |
|
| 3 |
import logging
|
| 4 |
-
from typing import Literal
|
| 5 |
|
| 6 |
from rich.console import Console
|
| 7 |
from rich.logging import RichHandler
|
|
@@ -23,6 +23,7 @@ def configure_logging(
|
|
| 23 |
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | int = "INFO",
|
| 24 |
logger: logging.Logger | None = None,
|
| 25 |
enable_rich_tracebacks: bool = True,
|
|
|
|
| 26 |
) -> None:
|
| 27 |
"""
|
| 28 |
Configure logging for FastMCP.
|
|
@@ -30,6 +31,7 @@ def configure_logging(
|
|
| 30 |
Args:
|
| 31 |
logger: the logger to configure
|
| 32 |
level: the log level to use
|
|
|
|
| 33 |
"""
|
| 34 |
|
| 35 |
if logger is None:
|
|
@@ -39,6 +41,7 @@ def configure_logging(
|
|
| 39 |
handler = RichHandler(
|
| 40 |
console=Console(stderr=True),
|
| 41 |
rich_tracebacks=enable_rich_tracebacks,
|
|
|
|
| 42 |
)
|
| 43 |
formatter = logging.Formatter("%(message)s")
|
| 44 |
handler.setFormatter(formatter)
|
|
|
|
| 1 |
"""Logging utilities for FastMCP."""
|
| 2 |
|
| 3 |
import logging
|
| 4 |
+
from typing import Any, Literal
|
| 5 |
|
| 6 |
from rich.console import Console
|
| 7 |
from rich.logging import RichHandler
|
|
|
|
| 23 |
level: Literal["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"] | int = "INFO",
|
| 24 |
logger: logging.Logger | None = None,
|
| 25 |
enable_rich_tracebacks: bool = True,
|
| 26 |
+
**rich_kwargs: Any,
|
| 27 |
) -> None:
|
| 28 |
"""
|
| 29 |
Configure logging for FastMCP.
|
|
|
|
| 31 |
Args:
|
| 32 |
logger: the logger to configure
|
| 33 |
level: the log level to use
|
| 34 |
+
rich_kwargs: the parameters to use for creating RichHandler
|
| 35 |
"""
|
| 36 |
|
| 37 |
if logger is None:
|
|
|
|
| 41 |
handler = RichHandler(
|
| 42 |
console=Console(stderr=True),
|
| 43 |
rich_tracebacks=enable_rich_tracebacks,
|
| 44 |
+
**rich_kwargs,
|
| 45 |
)
|
| 46 |
formatter = logging.Formatter("%(message)s")
|
| 47 |
handler.setFormatter(formatter)
|