From 161662dfaaff793cd0a149203fc30619a887b51f Mon Sep 17 00:00:00 2001 From: michaelxer Date: Sun, 7 Jun 2026 06:38:24 +0800 Subject: [PATCH] fix: respect NO_COLOR env var in logging format ANSI escape codes (\033[92m green, \033[0m reset) were hardcoded into the logging format string, producing garbled output when piped to files or when the NO_COLOR env var is set (https://no-color.org/). Now checks NO_COLOR and emits a plain format string when set, matching the existing convention in setup_wizard.py. Fixes #29799 --- litellm/_logging.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/litellm/_logging.py b/litellm/_logging.py index 6b99f50e014..2f8499161cb 100644 --- a/litellm/_logging.py +++ b/litellm/_logging.py @@ -249,8 +249,12 @@ if json_logs: handler.setFormatter(JsonFormatter()) _setup_json_exception_handlers(JsonFormatter()) else: + if 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" formatter = logging.Formatter( - "\033[92m%(asctime)s - %(name)s:%(levelname)s\033[0m: %(filename)s:%(lineno)s - %(message)s", + _format_str, datefmt="%H:%M:%S", )