[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:
co-authored by
AI Assistant
parent
fa6c407d15
commit
45d56c0baf
+60
-9
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user