fix: change performance log directory to cache path (#13482)

Co-authored-by: Mick <mickjagger19@icloud.com>
This commit is contained in:
Cheng Wan
2025-11-18 15:18:43 +08:00
committed by GitHub
co-authored by Mick
parent 4e41edcb9c
commit a5ad0069b2
4 changed files with 52 additions and 90 deletions
@@ -10,13 +10,28 @@ from typing import Any
from dateutil.tz import UTC
LOG_DIR = os.environ.get("SGLANG_PERF_LOG_DIR")
if LOG_DIR:
LOG_DIR = os.path.abspath(LOG_DIR)
elif LOG_DIR is None: # Not set
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../"))
LOG_DIR = os.path.join(project_root, "logs")
# if LOG_DIR is "", it will remain "", disabling file logging.
def get_diffusion_perf_log_dir() -> str:
"""
Determines the directory for performance logs, centralizing the logic.
Resolution order:
1. SGLANG_PERF_LOG_DIR environment variable, if set and not empty.
2. Default to ~/.cache/sglang/logs if the environment variable is not set.
3. Returns an empty string if SGLANG_PERF_LOG_DIR is set to an empty string,
which effectively disables file logging.
"""
log_dir = os.environ.get("SGLANG_PERF_LOG_DIR")
if log_dir:
return os.path.abspath(log_dir)
if log_dir is None:
# Not set, use default
return os.path.join(os.path.expanduser("~/.cache/sglang"), "logs")
# Is set, but is an empty string
return ""
LOG_DIR = get_diffusion_perf_log_dir()
# Configure a specific logger for performance metrics
perf_logger = logging.getLogger("performance")