@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / b5fb3005a8
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 14, 05:30 UTC

[Log] Use a relative path in debug-level logs to distinguish files with identical names (#23846)

Signed-off-by: zjy0516 <riverclouds.zhu@qq.com>

Jiangyun Zhu committed Sep 10, 2025 at 04:46 UTC b5fb3005a8624af171f12aaa6fb97557d91cbcd3
2 files changed +64 -3
vllm/logger.py
+1 -1
@@ -22,7 +22,7 @@ VLLM_LOGGING_LEVEL = envs.VLLM_LOGGING_LEVEL
22 VLLM_LOGGING_PREFIX = envs.VLLM_LOGGING_PREFIX
23
24 _FORMAT = (f"{VLLM_LOGGING_PREFIX}%(levelname)s %(asctime)s "
25 - "[%(filename)s:%(lineno)d] %(message)s")
25 + "[%(fileinfo)s:%(lineno)d] %(message)s")
26 _DATE_FORMAT = "%m-%d %H:%M:%S"
27
28 DEFAULT_LOGGING_CONFIG = {
vllm/logging_utils/formatter.py
+63 -2
@@ -2,16 +2,77 @@
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import logging
5 +from pathlib import Path
6 +
7 +from vllm import envs
8
9
10 class NewLineFormatter(logging.Formatter):
11 """Adds logging prefix to newlines to align multi-line messages."""
12
13 def __init__(self, fmt, datefmt=None, style="%"):
11 - logging.Formatter.__init__(self, fmt, datefmt, style)
14 + super().__init__(fmt, datefmt, style)
15 +
16 + self.use_relpath = envs.VLLM_LOGGING_LEVEL == "DEBUG"
17 + if self.use_relpath:
18 + self.root_dir = Path(__file__).resolve().parent.parent.parent
19
20 def format(self, record):
14 - msg = logging.Formatter.format(self, record)
21 +
22 + def shrink_path(relpath: Path) -> str:
23 + """
24 + Shortens a file path for logging display:
25 + - Removes leading 'vllm' folder if present.
26 + - If path starts with 'v1',
27 + keeps the first two and last two levels,
28 + collapsing the middle as '...'.
29 + - Otherwise, keeps the first and last two levels,
30 + collapsing the middle as '...'.
31 + - If the path is short, returns it as-is.
32 + - Examples:
33 + vllm/model_executor/layers/quantization/utils/fp8_utils.py ->
34 + model_executor/.../quantization/utils/fp8_utils.py
35 + vllm/model_executor/layers/quantization/awq.py ->
36 + model_executor/layers/quantization/awq.py
37 + vllm/v1/attention/backends/mla/common.py ->
38 + v1/attention/backends/mla/common.py
39 +
40 + Args:
41 + relpath (Path): The relative path to be shortened.
42 + Returns:
43 + str: The shortened path string for display.
44 + """
45 + parts = list(relpath.parts)
46 + new_parts = []
47 + if parts and parts[0] == "vllm":
48 + parts = parts[1:]
49 + if parts and parts[0] == "v1":
50 + new_parts += parts[:2]
51 + parts = parts[2:]
52 + elif parts:
53 + new_parts += parts[:1]
54 + parts = parts[1:]
55 + if len(parts) > 2:
56 + new_parts += ["..."] + parts[-2:]
57 + else:
58 + new_parts += parts
59 + return "/".join(new_parts)
60 +
61 + if self.use_relpath:
62 + abs_path = getattr(record, "pathname", None)
63 + if abs_path:
64 + try:
65 + relpath = Path(abs_path).resolve().relative_to(
66 + self.root_dir)
67 + except Exception:
68 + relpath = Path(record.filename)
69 + else:
70 + relpath = Path(record.filename)
71 + record.fileinfo = shrink_path(relpath)
72 + else:
73 + record.fileinfo = record.filename
74 +
75 + msg = super().format(record)
76 if record.message != "":
77 parts = msg.split(record.message)
78 msg = msg.replace("\n", "\r\n" + parts[0])