[Core][Logging] Add built-in JSON formatter (#58739)
Add `--logging-config.formatter=json` to enable the python-json-logger formatter without having to use a complete Python logging dictConfig. Signed-off-by: Mark McLoughlin <markmc@redhat.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
OpenAI Codex
parent
c4fc3c7d32
commit
91fcec1235
@@ -76,6 +76,8 @@ def test_logging_config_cli_args(serve_parser):
|
||||
[
|
||||
"--logging-config",
|
||||
'{"log_level":"WARNING","pylogging_config_file":"/tmp/json.json"}',
|
||||
"--logging-config.formatter",
|
||||
"json",
|
||||
"--log-level",
|
||||
"DEBUG",
|
||||
"--log-config-file",
|
||||
@@ -85,6 +87,7 @@ def test_logging_config_cli_args(serve_parser):
|
||||
|
||||
config = AsyncEngineArgs.from_cli_args(args).create_logging_config()
|
||||
assert config.log_level == "DEBUG"
|
||||
assert config.formatter == "json"
|
||||
assert config.pylogging_config_file == "/tmp/flat.json"
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import enum
|
||||
import io
|
||||
import json
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
@@ -21,6 +22,7 @@ from vllm.config import LoggingConfig
|
||||
from vllm.logger import (
|
||||
_DATE_FORMAT,
|
||||
_FORMAT,
|
||||
_JSON_FORMAT,
|
||||
_configure_vllm_root_logger,
|
||||
_use_color,
|
||||
configure_logging,
|
||||
@@ -204,6 +206,35 @@ def test_configure_logging_preserves_application_record_factory(
|
||||
logging.setLogRecordFactory(original_factory)
|
||||
|
||||
|
||||
def test_builtin_json_formatter(monkeypatch):
|
||||
output = io.StringIO()
|
||||
|
||||
try:
|
||||
with monkeypatch.context() as context:
|
||||
context.setattr(sys, "stdout", output)
|
||||
context.setattr(vllm_logger, "_vllm_process_info", None)
|
||||
_configure_vllm_root_logger(LoggingConfig(formatter="json"))
|
||||
decorate_logs("Worker_DP0")
|
||||
init_logger("vllm.structured_log_probe").info("structured log probe")
|
||||
|
||||
log = json.loads(output.getvalue())
|
||||
formatter = logging.getLogger("vllm").handlers[0].formatter
|
||||
finally:
|
||||
_configure_vllm_root_logger(LoggingConfig())
|
||||
|
||||
assert log == {
|
||||
"asctime": log["asctime"],
|
||||
"levelname": "INFO",
|
||||
"name": "vllm.structured_log_probe",
|
||||
"processName": multiprocessing.current_process().name,
|
||||
"process": os.getpid(),
|
||||
"message": "structured log probe",
|
||||
"vllm_process_name": "Worker_DP0",
|
||||
}
|
||||
assert formatter is not None
|
||||
assert formatter._fmt == _JSON_FORMAT
|
||||
|
||||
|
||||
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."""
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
"""Tests for the UvicornAccessLogFilter class."""
|
||||
"""Tests for Uvicorn logging configuration and access log filtering."""
|
||||
|
||||
import logging
|
||||
|
||||
from vllm.logging_utils.access_log_filter import (
|
||||
from vllm.logging_utils.uvicorn_logging import (
|
||||
UvicornAccessLogFilter,
|
||||
create_uvicorn_log_config,
|
||||
)
|
||||
Reference in New Issue
Block a user