From 7d8bd06252c192d0a3a869acd08e6b79870ed589 Mon Sep 17 00:00:00 2001 From: michaelxer Date: Sun, 7 Jun 2026 11:17:18 +0700 Subject: [PATCH] fix: also check isatty() for ANSI color in logging formatter Align with _supports_color() convention in setup_wizard.py which checks both sys.stdout.isatty() and NO_COLOR. This ensures piped/file output also gets plain text without ANSI escape codes. --- litellm/_logging.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/_logging.py b/litellm/_logging.py index 2f8499161cb..6ec7baeef91 100644 --- a/litellm/_logging.py +++ b/litellm/_logging.py @@ -249,7 +249,7 @@ if json_logs: handler.setFormatter(JsonFormatter()) _setup_json_exception_handlers(JsonFormatter()) else: - if os.environ.get("NO_COLOR") is None: + if sys.stdout.isatty() and os.environ.get("NO_COLOR") is None: _format_str = "\033[92m%(asctime)s - %(name)s:%(levelname)s\033[0m: %(filename)s:%(lineno)s - %(message)s" else: _format_str = "%(asctime)s - %(name)s:%(levelname)s: %(filename)s:%(lineno)s - %(message)s"