From 4e4436687b00a567da8e4035938464a043809d40 Mon Sep 17 00:00:00 2001 From: Ben Sully Date: Tue, 3 Dec 2024 16:19:29 +0000 Subject: [PATCH] fix: use stderr for logging Without this, logs get sent to stdout which is captured by the JSONRPC protocol (which also causes some errors with clients when the invalid JSON is sent over the stdout pipe). --- src/fastmcp/utilities/logging.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fastmcp/utilities/logging.py b/src/fastmcp/utilities/logging.py index e2dd5f45e..1535d1e56 100644 --- a/src/fastmcp/utilities/logging.py +++ b/src/fastmcp/utilities/logging.py @@ -3,6 +3,7 @@ import logging from typing import Literal +from rich.console import Console from rich.logging import RichHandler @@ -27,5 +28,7 @@ def configure_logging( level: the log level to use """ logging.basicConfig( - level=level, format="%(message)s", handlers=[RichHandler(rich_tracebacks=True)] + level=level, + format="%(message)s", + handlers=[RichHandler(console=Console(stderr=True), rich_tracebacks=True)], )