[Misc] Colorize logs (#29017)
Signed-off-by: Nick Hill <nhill@redhat.com>
This commit is contained in:
+51
-43
@@ -49,10 +49,13 @@ def test_trace_function_call():
|
||||
os.remove(path)
|
||||
|
||||
|
||||
def test_default_vllm_root_logger_configuration():
|
||||
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()
|
||||
|
||||
logger = logging.getLogger("vllm")
|
||||
assert logger.level == logging.DEBUG
|
||||
assert not logger.propagate
|
||||
@@ -70,12 +73,13 @@ def test_default_vllm_root_logger_configuration():
|
||||
assert formatter.datefmt == _DATE_FORMAT
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
@patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", None)
|
||||
def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger():
|
||||
def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger(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_CONFIGURE_LOGGING", "1")
|
||||
monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False)
|
||||
|
||||
root_logger = logging.getLogger("vllm")
|
||||
root_handler = root_logger.handlers[0]
|
||||
|
||||
@@ -99,49 +103,50 @@ def test_descendent_loggers_depend_on_and_propagate_logs_to_root_logger():
|
||||
assert log_record.levelno == logging.INFO
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 0)
|
||||
@patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", None)
|
||||
def test_logger_configuring_can_be_disabled():
|
||||
def test_logger_configuring_can_be_disabled(monkeypatch):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however mocks are used to ensure no changes in behavior or
|
||||
configuration occur."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "0")
|
||||
monkeypatch.delenv("VLLM_LOGGING_CONFIG_PATH", raising=False)
|
||||
|
||||
with patch("vllm.logger.dictConfig") as dict_config_mock:
|
||||
_configure_vllm_root_logger()
|
||||
dict_config_mock.assert_not_called()
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
@patch(
|
||||
"vllm.logger.VLLM_LOGGING_CONFIG_PATH",
|
||||
"/if/there/is/a/file/here/then/you/did/this/to/yourself.json",
|
||||
)
|
||||
def test_an_error_is_raised_when_custom_logging_config_file_does_not_exist():
|
||||
def test_an_error_is_raised_when_custom_logging_config_file_does_not_exist(monkeypatch):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however it fails before any change in behavior or
|
||||
configuration occurs."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1")
|
||||
monkeypatch.setenv(
|
||||
"VLLM_LOGGING_CONFIG_PATH",
|
||||
"/if/there/is/a/file/here/then/you/did/this/to/yourself.json",
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == RuntimeError # noqa: E721
|
||||
assert "File does not exist" in str(ex_info)
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
def test_an_error_is_raised_when_custom_logging_config_is_invalid_json():
|
||||
def test_an_error_is_raised_when_custom_logging_config_is_invalid_json(monkeypatch):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however it fails before any change in behavior or
|
||||
configuration occurs."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1")
|
||||
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write("---\nloggers: []\nversion: 1")
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(JSONDecodeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == JSONDecodeError
|
||||
assert "Expecting value" in str(ex_info)
|
||||
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
|
||||
with pytest.raises(JSONDecodeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == JSONDecodeError
|
||||
assert "Expecting value" in str(ex_info)
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
@pytest.mark.parametrize(
|
||||
"unexpected_config",
|
||||
(
|
||||
@@ -151,26 +156,30 @@ def test_an_error_is_raised_when_custom_logging_config_is_invalid_json():
|
||||
),
|
||||
)
|
||||
def test_an_error_is_raised_when_custom_logging_config_is_unexpected_json(
|
||||
monkeypatch,
|
||||
unexpected_config: Any,
|
||||
):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however it fails before any change in behavior or
|
||||
configuration occurs."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1")
|
||||
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(unexpected_config))
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(ValueError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == ValueError # noqa: E721
|
||||
assert "Invalid logging config. Expected dict, got" in str(ex_info)
|
||||
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
|
||||
with pytest.raises(ValueError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type == ValueError # noqa: E721
|
||||
assert "Invalid logging config. Expected dict, got" in str(ex_info)
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 1)
|
||||
def test_custom_logging_config_is_parsed_and_used_when_provided():
|
||||
def test_custom_logging_config_is_parsed_and_used_when_provided(monkeypatch):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however mocks are used to ensure no changes in behavior or
|
||||
configuration occur."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "1")
|
||||
|
||||
valid_logging_config = {
|
||||
"loggers": {
|
||||
"vllm.test_logger.logger": {
|
||||
@@ -183,19 +192,18 @@ def test_custom_logging_config_is_parsed_and_used_when_provided():
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(valid_logging_config))
|
||||
logging_config_file.flush()
|
||||
with (
|
||||
patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name),
|
||||
patch("vllm.logger.dictConfig") as dict_config_mock,
|
||||
):
|
||||
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
|
||||
with patch("vllm.logger.dictConfig") as dict_config_mock:
|
||||
_configure_vllm_root_logger()
|
||||
dict_config_mock.assert_called_with(valid_logging_config)
|
||||
|
||||
|
||||
@patch("vllm.logger.VLLM_CONFIGURE_LOGGING", 0)
|
||||
def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
|
||||
def test_custom_logging_config_causes_an_error_if_configure_logging_is_off(monkeypatch):
|
||||
"""This test calls _configure_vllm_root_logger again to test custom logging
|
||||
config behavior, however mocks are used to ensure no changes in behavior or
|
||||
configuration occur."""
|
||||
monkeypatch.setenv("VLLM_CONFIGURE_LOGGING", "0")
|
||||
|
||||
valid_logging_config = {
|
||||
"loggers": {
|
||||
"vllm.test_logger.logger": {
|
||||
@@ -207,15 +215,15 @@ def test_custom_logging_config_causes_an_error_if_configure_logging_is_off():
|
||||
with NamedTemporaryFile(encoding="utf-8", mode="w") as logging_config_file:
|
||||
logging_config_file.write(json.dumps(valid_logging_config))
|
||||
logging_config_file.flush()
|
||||
with patch("vllm.logger.VLLM_LOGGING_CONFIG_PATH", logging_config_file.name):
|
||||
with pytest.raises(RuntimeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type is RuntimeError
|
||||
expected_message_snippet = (
|
||||
"VLLM_CONFIGURE_LOGGING evaluated to false, but "
|
||||
"VLLM_LOGGING_CONFIG_PATH was given."
|
||||
)
|
||||
assert expected_message_snippet in str(ex_info)
|
||||
monkeypatch.setenv("VLLM_LOGGING_CONFIG_PATH", logging_config_file.name)
|
||||
with pytest.raises(RuntimeError) as ex_info:
|
||||
_configure_vllm_root_logger()
|
||||
assert ex_info.type is RuntimeError
|
||||
expected_message_snippet = (
|
||||
"VLLM_CONFIGURE_LOGGING evaluated to false, but "
|
||||
"VLLM_LOGGING_CONFIG_PATH was given."
|
||||
)
|
||||
assert expected_message_snippet in str(ex_info)
|
||||
|
||||
# Remember! The root logger is assumed to have been configured as
|
||||
# though VLLM_CONFIGURE_LOGGING=1 and VLLM_LOGGING_CONFIG_PATH=None.
|
||||
|
||||
Reference in New Issue
Block a user