Skip to content

vllm.logging_utils

Modules:

Classes:

Functions:

  • create_uvicorn_log_config –

    Create a uvicorn logging configuration with optional access filtering.

  • logtime –

    Logs the execution time of the decorated function.

ColoredFormatter

Bases: NewLineFormatter

Adds ANSI color codes to log levels for terminal output.

This formatter adds colors by injecting them into the format string for static elements (timestamp, filename, line number) and modifying the levelname attribute for dynamic color selection.

NewLineFormatter

Bases: Formatter

Adds logging prefix to newlines to align multi-line messages.

UvicornAccessLogFilter

Bases: Filter

A logging filter that excludes access logs for specified endpoint paths.

This filter is designed to work with uvicorn's access logger. It checks the log record's arguments for the request path and filters out records matching the excluded paths.

Uvicorn access log format

'%s - "%s %s HTTP/%s" %d' (client_addr, method, path, http_version, status_code)

Example

127.0.0.1:12345 - "GET /health HTTP/1.1" 200

Parameters:

  • excluded_paths

    (list[str] | None, default: None ) –

    A list of URL paths to exclude from logging. Paths are matched exactly. Example: ["/health", "/metrics"]

Methods:

  • filter –

    Determine if the log record should be logged.

filter(record)

Determine if the log record should be logged.

Parameters:

  • record

    (LogRecord) –

    The log record to evaluate.

Returns:

  • bool –

    True if the record should be logged, False otherwise.

create_uvicorn_log_config(excluded_paths=None, log_level='info', formatter='text')

Create a uvicorn logging configuration with optional access filtering.

This function generates a logging configuration dictionary that can be passed to uvicorn's log_config parameter. It sets up the access log filter to exclude specified paths.

Parameters:

  • excluded_paths

    (list[str] | None, default: None ) –

    List of URL paths to exclude from access logs.

  • log_level

    (str, default: 'info' ) –

    The log level for uvicorn loggers.

  • formatter

    (Literal['text', 'json'], default: 'text' ) –

    Format used for uvicorn logs.

Returns:

  • dict –

    A dictionary containing the logging configuration.

Example

config = create_uvicorn_log_config(["/health", "/metrics"]) uvicorn.run(app, log_config=config)

logtime(logger, msg=None)

Logs the execution time of the decorated function. Always place it beneath other decorators.