Skip to content

vllm.logger

Logging configuration for vLLM.

_VllmLogger

Bases: Logger

Note

This class is just to provide type information. We actually patch the methods directly on the logging.Logger instance to avoid conflicting with other libraries such as intel_extension_for_pytorch.utils._logger.

Source code in vllm/logger.py
class _VllmLogger(Logger):
    """
    Note:
        This class is just to provide type information.
        We actually patch the methods directly on the [`logging.Logger`][]
        instance to avoid conflicting with other libraries such as
        `intel_extension_for_pytorch.utils._logger`.
    """

    def debug_once(
        self, msg: str, *args: Hashable, scope: LogScope = "process"
    ) -> None:
        """
        As [`debug`][logging.Logger.debug], but subsequent calls with
        the same message are silently dropped.
        """
        if not _should_log_with_scope(scope):
            return
        _print_debug_once(self, msg, *args)

    def info_once(self, msg: str, *args: Hashable, scope: LogScope = "process") -> None:
        """
        As [`info`][logging.Logger.info], but subsequent calls with
        the same message are silently dropped.
        """
        if not _should_log_with_scope(scope):
            return
        _print_info_once(self, msg, *args)

    def warning_once(
        self, msg: str, *args: Hashable, scope: LogScope = "process"
    ) -> None:
        """
        As [`warning`][logging.Logger.warning], but subsequent calls with
        the same message are silently dropped.
        """
        if not _should_log_with_scope(scope):
            return
        _print_warning_once(self, msg, *args)

debug_once

debug_once(
    msg: str, *args: Hashable, scope: LogScope = "process"
) -> None

As debug, but subsequent calls with the same message are silently dropped.

Source code in vllm/logger.py
def debug_once(
    self, msg: str, *args: Hashable, scope: LogScope = "process"
) -> None:
    """
    As [`debug`][logging.Logger.debug], but subsequent calls with
    the same message are silently dropped.
    """
    if not _should_log_with_scope(scope):
        return
    _print_debug_once(self, msg, *args)

info_once

info_once(
    msg: str, *args: Hashable, scope: LogScope = "process"
) -> None

As info, but subsequent calls with the same message are silently dropped.

Source code in vllm/logger.py
def info_once(self, msg: str, *args: Hashable, scope: LogScope = "process") -> None:
    """
    As [`info`][logging.Logger.info], but subsequent calls with
    the same message are silently dropped.
    """
    if not _should_log_with_scope(scope):
        return
    _print_info_once(self, msg, *args)

warning_once

warning_once(
    msg: str, *args: Hashable, scope: LogScope = "process"
) -> None

As warning, but subsequent calls with the same message are silently dropped.

Source code in vllm/logger.py
def warning_once(
    self, msg: str, *args: Hashable, scope: LogScope = "process"
) -> None:
    """
    As [`warning`][logging.Logger.warning], but subsequent calls with
    the same message are silently dropped.
    """
    if not _should_log_with_scope(scope):
        return
    _print_warning_once(self, msg, *args)

_should_log_with_scope

_should_log_with_scope(scope: LogScope) -> bool

Decide whether to log based on scope

Source code in vllm/logger.py
def _should_log_with_scope(scope: LogScope) -> bool:
    """Decide whether to log based on scope"""
    if scope == "global":
        from vllm.distributed.parallel_state import is_global_first_rank

        return is_global_first_rank()
    if scope == "local":
        from vllm.distributed.parallel_state import is_local_first_rank

        return is_local_first_rank()
    # default "process" scope: always log
    return True

enable_trace_function_call

enable_trace_function_call(
    log_file_path: str, root_dir: str | None = None
)

Enable tracing of every function call in code under root_dir. This is useful for debugging hangs or crashes. log_file_path is the path to the log file. root_dir is the root directory of the code to trace. If None, it is the vllm root directory.

Note that this call is thread-level, any threads calling this function will have the trace enabled. Other threads will not be affected.

Source code in vllm/logger.py
def enable_trace_function_call(log_file_path: str, root_dir: str | None = None):
    """
    Enable tracing of every function call in code under `root_dir`.
    This is useful for debugging hangs or crashes.
    `log_file_path` is the path to the log file.
    `root_dir` is the root directory of the code to trace. If None, it is the
    vllm root directory.

    Note that this call is thread-level, any threads calling this function
    will have the trace enabled. Other threads will not be affected.
    """
    logger.warning(
        "VLLM_TRACE_FUNCTION is enabled. It will record every"
        " function executed by Python. This will slow down the code. It "
        "is suggested to be used for debugging hang or crashes only."
    )
    logger.info("Trace frame log is saved to %s", log_file_path)
    if root_dir is None:
        # by default, this is the vllm root directory
        root_dir = os.path.dirname(os.path.dirname(__file__))
    sys.settrace(partial(_trace_calls, log_file_path, root_dir))

init_logger

init_logger(name: str) -> _VllmLogger

The main purpose of this function is to ensure that loggers are retrieved in such a way that we can be sure the root vllm logger has already been configured.

Source code in vllm/logger.py
def init_logger(name: str) -> _VllmLogger:
    """The main purpose of this function is to ensure that loggers are
    retrieved in such a way that we can be sure the root vllm logger has
    already been configured."""

    logger = logging.getLogger(name)

    for method_name, method in _METHODS_TO_PATCH.items():
        setattr(logger, method_name, MethodType(method, logger))

    return cast(_VllmLogger, logger)