fix: 日志目录去掉硬编码 /home/xsl,改为基于仓库根解析(支持 HAIR_LOG_DIR 覆盖)
worker 部署到 /home/ubuntu 等其他路径时,原硬编码 /home/xsl/hair/log 会导致 Permission denied。改为相对仓库根,兼容多机部署。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1682,13 +1682,17 @@ async def hairline_grow_v2_final_v2(
|
||||
|
||||
@app.get("/api/v1/debug/hairline_log", include_in_schema=False)
|
||||
async def download_hairline_log(rid: Optional[str] = None, tail: int = 500):
|
||||
"""返回 /home/xsl/hair/log/hairline_grow.log 的内容。
|
||||
"""返回 <仓库根>/log/hairline_grow.log 的内容。
|
||||
|
||||
rid 非空时只返回该 request id 相关的行;tail 限制返回最后 N 行(默认 500)。
|
||||
供调试页"下载日志"按钮调用。
|
||||
"""
|
||||
from fastapi.responses import PlainTextResponse
|
||||
log_path = "/home/xsl/hair/log/hairline_grow.log"
|
||||
log_path = os.getenv(
|
||||
"HAIR_LOG_DIR",
|
||||
os.path.join(os.path.dirname(os.path.abspath(__file__)), "log"),
|
||||
)
|
||||
log_path = os.path.join(log_path, "hairline_grow.log")
|
||||
try:
|
||||
with open(log_path, encoding="utf-8") as fh:
|
||||
lines = fh.readlines()
|
||||
|
||||
@@ -47,8 +47,11 @@ from face_analysis.head_mask import (
|
||||
_draw_baseline,
|
||||
)
|
||||
|
||||
# 调试日志:写 /home/xsl/hair/log/hairline_grow.log,每个步骤详细记录
|
||||
_LOG_DIR = "/home/xsl/hair/log"
|
||||
# 调试日志:写 <仓库根>/log/hairline_grow.log,每个步骤详细记录(可用 HAIR_LOG_DIR 覆盖)
|
||||
_LOG_DIR = os.getenv(
|
||||
"HAIR_LOG_DIR",
|
||||
os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "log"),
|
||||
)
|
||||
os.makedirs(_LOG_DIR, exist_ok=True)
|
||||
logger = logging.getLogger("hairline_grow")
|
||||
_log_fh = logging.FileHandler(os.path.join(_LOG_DIR, "hairline_grow.log"), encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user