[Core] Model console logging as CLI configuration (#57205)

Add `--logging-config` CLI argument which can be supplied as
JSON or using dotted arguments. The `--log-level` argument
is provided for convenience, and `--log-config-file` is deprecated
in favor of `--logging-config.pylogging_config_file`.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Co-authored-by: AI Assistant <noreply@openai.com>
This commit is contained in:
Mark McLoughlin
2026-09-25 11:36:59 +01:00
committed by GitHub
co-authored by AI Assistant
parent fa6c407d15
commit 45d56c0baf
36 changed files with 439 additions and 134 deletions
+8 -4
View File
@@ -1430,16 +1430,20 @@ def temporary_enable_log_propagate():
import logging
logger = logging.getLogger("vllm")
previous_propagate = logger.propagate
logger.propagate = True
yield
logger.propagate = False
logger.propagate = previous_propagate
@pytest.fixture()
def caplog_vllm(temporary_enable_log_propagate, caplog):
# To capture vllm log, we should enable propagate=True temporarily
# because caplog depends on logs propagated to the root logger.
yield caplog
# caplog depends on logs propagated to the root logger. The vLLM logger
# inherits this INFO level until runtime initialization configures it.
import logging
with caplog.at_level(logging.INFO):
yield caplog
@pytest.fixture()
@@ -8,6 +8,7 @@ import pytest
import vllm.entrypoints.launchers.cli_args as cli_args_module
from tests.utils import VLLM_PATH
from vllm.engine.arg_utils import AsyncEngineArgs
from vllm.entrypoints.launchers.cli_args import (
make_arg_parser,
validate_parsed_serve_args,
@@ -69,6 +70,24 @@ def test_config_arg_parsing(serve_parser, cli_config_file):
assert args.port == 9000
def test_logging_config_cli_args(serve_parser):
with pytest.warns(UserWarning, match="--log-config-file is deprecated"):
args = serve_parser.parse_args(
[
"--logging-config",
'{"log_level":"WARNING","pylogging_config_file":"/tmp/json.json"}',
"--log-level",
"DEBUG",
"--log-config-file",
"/tmp/flat.json",
]
)
config = AsyncEngineArgs.from_cli_args(args).create_logging_config()
assert config.log_level == "DEBUG"
assert config.pylogging_config_file == "/tmp/flat.json"
### Tests for LoRA module parsing
def test_valid_key_value_format(serve_parser):
# Test old format: name=path
+60 -9
View File
@@ -16,11 +16,13 @@ from uuid import uuid4
import pytest
from vllm.config import LoggingConfig
from vllm.logger import (
_DATE_FORMAT,
_FORMAT,
_configure_vllm_root_logger,
_use_color,
configure_logging,
enable_trace_function_call,
init_logger,
)
@@ -50,16 +52,27 @@ def test_trace_function_call():
os.remove(path)
def test_caplog_vllm_captures_info_before_runtime_logging_is_configured(caplog_vllm):
message = "Capture this unconfigured INFO record"
logger = init_logger(f"vllm.test_logger.{uuid4()}")
logger.info(message)
assert message in caplog_vllm.text
def test_default_vllm_root_logger_configuration(monkeypatch):
"""This test presumes that VLLM_CONFIGURE_LOGGING (default: True) and
VLLM_LOGGING_CONFIG_PATH (default: None) are not configured and default
behavior is activated."""
monkeypatch.setenv("VLLM_LOGGING_COLOR", "0")
_configure_vllm_root_logger()
early_logger = init_logger(f"vllm.test_logger.{uuid4()}")
configure_logging(LoggingConfig())
logger = logging.getLogger("vllm")
assert logger.level == logging.INFO
assert not logger.propagate
assert early_logger.isEnabledFor(logging.INFO)
handler = logger.handlers[0]
assert isinstance(handler, logging.StreamHandler)
@@ -74,6 +87,29 @@ def test_default_vllm_root_logger_configuration(monkeypatch):
assert formatter.datefmt == _DATE_FORMAT
def test_offline_llm_configures_logging_before_logging_args(monkeypatch):
import vllm.entrypoints.llm as llm_module
class StopInitialization(Exception):
pass
configured = False
def configure_logging(_):
nonlocal configured
configured = True
def log_args(_):
assert configured
raise StopInitialization
monkeypatch.setattr(llm_module, "configure_logging_if_needed", configure_logging)
monkeypatch.setattr(llm_module, "log_non_default_args", log_args)
with pytest.raises(StopInitialization):
llm_module.LLM(model="facebook/opt-125m")
def test_use_color_force_color(monkeypatch):
"""FORCE_COLOR forces colored logs without a TTY, while NO_COLOR and an
explicit VLLM_LOGGING_COLOR=0 take precedence over it."""
@@ -133,7 +169,7 @@ def test_logger_configuring_can_be_disabled(monkeypatch):
monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False)
with patch("vllm.logger.dictConfig") as dict_config_mock:
_configure_vllm_root_logger()
configure_logging(LoggingConfig(configure_logging=False))
dict_config_mock.assert_not_called()
@@ -214,9 +250,11 @@ def test_custom_logging_config_is_parsed_and_used_when_provided(monkeypatch):
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
logging_config_file.write(json.dumps(valid_logging_config))
logging_config_file.flush()
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False)
with patch("vllm.logger.dictConfig") as dict_config_mock:
_configure_vllm_root_logger()
configure_logging(
LoggingConfig(pylogging_config_file=logging_config_file.name)
)
dict_config_mock.assert_called_with(valid_logging_config)
@@ -237,13 +275,18 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off(monke
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
logging_config_file.write(json.dumps(valid_logging_config))
logging_config_file.flush()
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False)
with pytest.raises(RuntimeError) as ex_info:
_configure_vllm_root_logger()
configure_logging(
LoggingConfig(
configure_logging=False,
pylogging_config_file=logging_config_file.name,
)
)
assert ex_info.type is RuntimeError
expected_message_snippet = (
"VLLM_CONFIGURE_LOGGING evaluated to false, but "
"VLLM_LOGGING_CONFIG_PATH was given."
"Logging configuration is disabled, but a Python logging config "
"file was given."
)
assert expected_message_snippet in str(ex_info)
@@ -297,6 +340,8 @@ test_logger = init_logger("vllm.test_logger")
def mp_function(**kwargs):
# This function runs in a subprocess
if logging_config := kwargs.pop("logging_config", None):
configure_logging(logging_config)
test_logger.warning("This is a subprocess: %s", kwargs.get("a"))
test_logger.error("This is a subprocess error.")
@@ -328,7 +373,13 @@ def test_caplog_mp_spawn(caplog_mp_spawn):
p = ctx.Process(
target=mp_function,
name=f"SubProcess{1}",
kwargs={"a": "AAAA", "b": "BBBBB"},
kwargs={
"a": "AAAA",
"b": "BBBBB",
"logging_config": LoggingConfig(
pylogging_config_file=os.environ["VLLM_LOGGING_CONFIG_PATH"]
),
},
)
p.start()
p.join()
+3 -1
View File
@@ -11,7 +11,7 @@ import pytest
import vllm.v1.engine.async_llm as async_llm_module
from vllm import SamplingParams
from vllm.assets.image import ImageAsset
from vllm.config import VllmConfig
from vllm.config import LoggingConfig, VllmConfig
from vllm.engine.arg_utils import AsyncEngineArgs
from vllm.entrypoints.openai.chat_completion.protocol import (
ChatCompletionRequest,
@@ -89,6 +89,7 @@ def _mock_async_llm_dependencies(monkeypatch: pytest.MonkeyPatch):
def test_cuda_profiler_requests_reach_engine_core(monkeypatch: pytest.MonkeyPatch):
vllm_config = MagicMock()
vllm_config.logging_config = LoggingConfig()
vllm_config.observability_config.otlp_traces_endpoint = None
vllm_config.scheduler_config.stream_interval = 1
vllm_config.profiler_config.profiler = "cuda"
@@ -111,6 +112,7 @@ def test_cuda_only_torch_profiler_skips_frontend_cpu_trace(
monkeypatch: pytest.MonkeyPatch,
):
vllm_config = MagicMock()
vllm_config.logging_config = LoggingConfig()
vllm_config.observability_config.otlp_traces_endpoint = None
vllm_config.scheduler_config.stream_interval = 1
vllm_config.profiler_config.profiler = "torch"