mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
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
This commit is contained in:
parent
68d67212cd
commit
161662dfaa
1 changed files with 5 additions and 1 deletions
|
|
@ -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",
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue