[Feature][Frontend] Control the log level of request JSON body using env var (#60630)

Signed-off-by: talora <talora@nvidia.com>
This commit is contained in:
Talor Abramovich
2026-10-15 11:07:19 +00:00
committed by GitHub
parent 365aaa77bd
commit 81e42c9987
4 changed files with 28 additions and 8 deletions
@@ -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]
+3 -1
View File
@@ -3242,7 +3242,9 @@ class AsyncEngineArgs(EngineArgs):
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
+16 -5
View File
@@ -6,6 +6,7 @@ from collections.abc import Sequence
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
@@ -70,12 +71,22 @@ class RequestLogger:
)
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,
+6
View File
@@ -331,6 +331,7 @@ if TYPE_CHECKING:
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():
@@ -2264,6 +2265,10 @@ environment_variables: dict[str, Callable[[], Any]] = {
"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(),
}
@@ -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