Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/entrypoints/serve/utils/test_request_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def test_request_logger_log_request_body_truncation(max_log_len):
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]
mock_logger.log.assert_called_once()
assert mock_logger.log.call_args.args[0] == logging.DEBUG
logged_body = mock_logger.log.call_args.args[3]
assert logged_body == full_body[:max_log_len]
4 changes: 3 additions & 1 deletion vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3242,7 +3242,9 @@ def add_cli_args(
help="Enable logging request information, dependent on log level:\n"
"- INFO: Request ID, parameters and LoRA request.\n"
"- DEBUG: Prompt inputs (e.g: text, token IDs).\n"
"You can set the minimum log level via `VLLM_LOGGING_LEVEL`.",
"You can set the minimum log level via `VLLM_LOGGING_LEVEL`.\n"
"You can also set a separate log level for request JSON body "
"via `VLLM_REQUEST_BODY_LOG_LEVEL` (default: DEBUG).",
)
current_platform.pre_register_and_update(parser)
return parser
Expand Down
21 changes: 16 additions & 5 deletions vllm/entrypoints/serve/utils/request_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import torch

from vllm import envs
from vllm.entrypoints.pooling.typing import AnyPoolingRequest
from vllm.entrypoints.serve.engine.typing import AnyRequest
from vllm.logger import init_logger
Expand Down Expand Up @@ -70,12 +71,22 @@ def log_inputs(
)

def log_request_body(self, request: AnyRequest | AnyPoolingRequest) -> None:
if logger.isEnabledFor(logging.DEBUG):
logger.debug(
"Request %s JSON body: %s",
getattr(request, "request_id", "N/A"),
request.model_dump_json(exclude_unset=True)[: self.max_log_len],
try:
level = logging.getLevelNamesMapping()[envs.VLLM_REQUEST_BODY_LOG_LEVEL]
except KeyError:
logger.warning_once(
"Invalid logging level for request content: %s. "
"Request JSON body will not be logged.",
envs.VLLM_REQUEST_BODY_LOG_LEVEL,
)
return

logger.log(
level,
"Request %s JSON body: %s",
getattr(request, "request_id", "N/A"),
request.model_dump_json(exclude_unset=True)[: self.max_log_len],
)

def log_outputs(
self,
Expand Down
6 changes: 6 additions & 0 deletions vllm/envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@
VLLM_GPU_NIC_PCIE_MAPPING: str = ""
VLLM_NIC_SELECTION_VARS: str = ""
VLLM_ENABLE_HPC_OPS: bool = False
VLLM_REQUEST_BODY_LOG_LEVEL: str = "DEBUG"


def get_default_cache_root():
Expand Down Expand Up @@ -2264,6 +2265,10 @@ def _resolve_rust_cli_path() -> str | None:
"VLLM_SKIP_VERSION_SUFFIX": lambda: bool(
int(os.getenv("VLLM_SKIP_VERSION_SUFFIX", "0"))
),
# Logging level for request JSON body.
"VLLM_REQUEST_BODY_LOG_LEVEL": lambda: os.getenv(
"VLLM_REQUEST_BODY_LOG_LEVEL", "DEBUG"
).upper(),
}


Expand Down Expand Up @@ -2423,6 +2428,7 @@ def compile_factors() -> dict[str, object]:
"NO_COLOR",
"VLLM_SKIP_VERSION_SUFFIX",
"FORCE_COLOR",
"VLLM_REQUEST_BODY_LOG_LEVEL",
}

from vllm.config.utils import normalize_value
Expand Down
Loading