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.
This commit is contained in:
michaelxer 2026-06-07 11:17:18 +07:00
parent 161662dfaa
commit 7d8bd06252

View file

@ -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"