""" Per-job structured logging so an Agent can debug a failed render by reading logs/{job_id}.log. Every pipeline stage writes through job_log(). """ import datetime import os LOG_DIR = "logs" def job_log(job_id: str, message: str, stage: str = ""): os.makedirs(LOG_DIR, exist_ok=True) ts = datetime.datetime.utcnow().isoformat() prefix = f"[{stage}] " if stage else "" line = f"{ts} {prefix}{message}\n" with open(os.path.join(LOG_DIR, f"{job_id}.log"), "a") as f: f.write(line) print(f"[{job_id}] {prefix}{message}")