[Bugfix][Frontend] Log the full request body when max_log_len is unset (#60310)
Signed-off-by: sricursion <sricursion@gmail.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
@@ -4,6 +4,9 @@
|
||||
import logging
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from vllm.entrypoints.openai.completion.protocol import CompletionRequest
|
||||
from vllm.entrypoints.serve.utils.request_logger import RequestLogger
|
||||
|
||||
|
||||
@@ -269,3 +272,18 @@ def test_streaming_complete_logs_full_text_content():
|
||||
assert call_args[1] == "test-streaming-full-text"
|
||||
assert call_args[2] == " (streaming complete)"
|
||||
assert call_args[4] == "streaming_complete"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("max_log_len", [None, 10])
|
||||
def test_request_logger_log_request_body_truncation(max_log_len):
|
||||
"""The JSON body is logged in full unless max_log_len truncates it."""
|
||||
request = CompletionRequest(model="test-model", prompt="Hello, world!")
|
||||
full_body = request.model_dump_json(exclude_unset=True)
|
||||
mock_logger = MagicMock()
|
||||
|
||||
with patch("vllm.entrypoints.serve.utils.request_logger.logger", mock_logger):
|
||||
RequestLogger(max_log_len=max_log_len).log_request_body(request)
|
||||
|
||||
mock_logger.debug.assert_called_once()
|
||||
logged_body = mock_logger.debug.call_args.args[2]
|
||||
assert logged_body == full_body[:max_log_len]
|
||||
|
||||
@@ -71,11 +71,10 @@ class RequestLogger:
|
||||
|
||||
def log_request_body(self, request: AnyRequest | AnyPoolingRequest) -> None:
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
max_log_len = self.max_log_len if self.max_log_len is not None else -1
|
||||
logger.debug(
|
||||
"Request %s JSON body: %s",
|
||||
getattr(request, "request_id", "N/A"),
|
||||
request.model_dump_json(exclude_unset=True)[:max_log_len],
|
||||
request.model_dump_json(exclude_unset=True)[: self.max_log_len],
|
||||
)
|
||||
|
||||
def log_outputs(
|
||||
|
||||
Reference in New Issue
Block a user