Skip to content

Commit b540786

Browse files
elizabeththmellorcboss6ywang96janeyx99
authored
[Bugfix] Respect VLLM_CONFIGURE_LOGGING value (#28671)
Signed-off-by: Elizabeth Thomas <email2eliza@gmail.com> Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Signed-off-by: Roger Wang <hey@rogerw.io> Signed-off-by: Jane Xu <janeyx@meta.com> Signed-off-by: Nick Hill <nhill@redhat.com> Signed-off-by: Johnny Yang <johnnyyang@google.com> Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: bruceszchen <bruceszchen@tencent.com> Co-authored-by: Roger Wang <hey@rogerw.io> Co-authored-by: Jane (Yuan) Xu <31798555+janeyx99@users.noreply.github.com> Co-authored-by: Nick Hill <nhill@redhat.com> Co-authored-by: Johnny Yang <24908445+jcyang43@users.noreply.github.com>
1 parent 2902c34 commit b540786

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

tests/test_envs.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,54 @@ def test_duplicate_values_deduped(self):
365365
with patch.dict(os.environ, {"TEST_ENV": "option1,option1,option2"}):
366366
env_func = env_set_with_choices("TEST_ENV", [], ["option1", "option2"])
367367
assert env_func() == {"option1", "option2"}
368+
369+
370+
class TestVllmConfigureLogging:
371+
"""Test cases for VLLM_CONFIGURE_LOGGING environment variable."""
372+
373+
def test_configure_logging_defaults_to_true(self):
374+
"""Test that VLLM_CONFIGURE_LOGGING defaults to True when not set."""
375+
# Ensure the env var is not set
376+
with patch.dict(os.environ, {}, clear=False):
377+
if "VLLM_CONFIGURE_LOGGING" in os.environ:
378+
del os.environ["VLLM_CONFIGURE_LOGGING"]
379+
380+
# Clear cache if it exists
381+
if hasattr(envs.__getattr__, "cache_clear"):
382+
envs.__getattr__.cache_clear()
383+
384+
result = envs.VLLM_CONFIGURE_LOGGING
385+
assert result is True
386+
assert isinstance(result, bool)
387+
388+
def test_configure_logging_with_zero_string(self):
389+
"""Test that VLLM_CONFIGURE_LOGGING='0' evaluates to False."""
390+
with patch.dict(os.environ, {"VLLM_CONFIGURE_LOGGING": "0"}):
391+
# Clear cache if it exists
392+
if hasattr(envs.__getattr__, "cache_clear"):
393+
envs.__getattr__.cache_clear()
394+
395+
result = envs.VLLM_CONFIGURE_LOGGING
396+
assert result is False
397+
assert isinstance(result, bool)
398+
399+
def test_configure_logging_with_one_string(self):
400+
"""Test that VLLM_CONFIGURE_LOGGING='1' evaluates to True."""
401+
with patch.dict(os.environ, {"VLLM_CONFIGURE_LOGGING": "1"}):
402+
# Clear cache if it exists
403+
if hasattr(envs.__getattr__, "cache_clear"):
404+
envs.__getattr__.cache_clear()
405+
406+
result = envs.VLLM_CONFIGURE_LOGGING
407+
assert result is True
408+
assert isinstance(result, bool)
409+
410+
def test_configure_logging_with_invalid_value_raises_error(self):
411+
"""Test that invalid VLLM_CONFIGURE_LOGGING value raises ValueError."""
412+
with patch.dict(os.environ, {"VLLM_CONFIGURE_LOGGING": "invalid"}):
413+
# Clear cache if it exists
414+
if hasattr(envs.__getattr__, "cache_clear"):
415+
envs.__getattr__.cache_clear()
416+
417+
with pytest.raises(ValueError, match="invalid literal for int"):
418+
_ = envs.VLLM_CONFIGURE_LOGGING

vllm/envs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
VLLM_DISABLE_FLASHINFER_PREFILL: bool = False
3838
VLLM_DO_NOT_TRACK: bool = False
3939
VLLM_USAGE_SOURCE: str = ""
40-
VLLM_CONFIGURE_LOGGING: int = 1
40+
VLLM_CONFIGURE_LOGGING: bool = True
4141
VLLM_LOGGING_LEVEL: str = "INFO"
4242
VLLM_LOGGING_PREFIX: str = ""
4343
VLLM_LOGGING_STREAM: str = "ext://sys.stdout"
@@ -623,7 +623,9 @@ def get_vllm_port() -> int | None:
623623
# If set to 0, vllm will not configure logging
624624
# If set to 1, vllm will configure logging using the default configuration
625625
# or the configuration file specified by VLLM_LOGGING_CONFIG_PATH
626-
"VLLM_CONFIGURE_LOGGING": lambda: int(os.getenv("VLLM_CONFIGURE_LOGGING", "1")),
626+
"VLLM_CONFIGURE_LOGGING": lambda: bool(
627+
int(os.getenv("VLLM_CONFIGURE_LOGGING", "1"))
628+
),
627629
"VLLM_LOGGING_CONFIG_PATH": lambda: os.getenv("VLLM_LOGGING_CONFIG_PATH"),
628630
# this is used for configuring the default logging level
629631
"VLLM_LOGGING_LEVEL": lambda: os.getenv("VLLM_LOGGING_LEVEL", "INFO").upper(),

vllm/utils/system_utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ def write_with_prefix(s: str):
204204

205205
def decorate_logs(process_name: str | None = None) -> None:
206206
"""Decorate stdout/stderr with process name and PID prefix."""
207+
# Respect VLLM_CONFIGURE_LOGGING environment variable
208+
if not envs.VLLM_CONFIGURE_LOGGING:
209+
return
210+
207211
if process_name is None:
208212
process_name = get_mp_context().current_process().name
209213

0 commit comments

Comments
 (0)