[Bugfix] Fix missing ANSI colors in CLI logo when output is piped (#1636)

Signed-off-by: Lidang-Jiang <lidangjiang@gmail.com>
This commit is contained in:
Lidang Jiang authored and GitHub committed 2026-05-06 15:43:19 +00:00
1 parent 576afb6f53
commit b8bd75837e
2 files changed
+17 -2

No files matched your search

+9 -2
View File
@@ -1,6 +1,7 @@
import os
import re
from vllm.logger import current_formatter_type, init_logger
from vllm.logger import init_logger
logger = init_logger(__name__)
@@ -41,5 +42,11 @@ _ANSI_RE = re.compile(r"\033\[[0-9;]*m")
def log_logo() -> None:
logo = LOGO if current_formatter_type(logger) == "color" else _ANSI_RE.sub("", LOGO)
# Bypass current_formatter_type() which has fragile handler-count/name
# checks that fail in some runtime configurations. Instead, directly
# check the env vars that control colored output — matching vLLM's
# _use_color() logic. main.py sets VLLM_LOGGING_COLOR=1 before any
# vLLM import, so this env var is the authoritative source of truth.
use_color = "NO_COLOR" not in os.environ and os.environ.get("VLLM_LOGGING_COLOR") != "0"
logo = LOGO if use_color else _ANSI_RE.sub("", LOGO)
logger.info(logo)
+8
View File
@@ -15,6 +15,14 @@ def main():
vllm_main()
return
else:
# Force colored logging even when piped (e.g. `| tee`).
# Must be set before any vLLM import because the logger
# formatter is configured at import time via _use_color().
import os
if "VLLM_LOGGING_COLOR" not in os.environ:
os.environ["VLLM_LOGGING_COLOR"] = "1"
from vllm.entrypoints.utils import VLLM_SUBCMD_PARSER_EPILOG, cli_env_setup
from vllm.utils.argparse_utils import FlexibleArgumentParser