from __future__ import annotations import os from pathlib import Path def _log_path() -> Path | None: raw = str(os.getenv("MESA_STARTUP_LOG_FILE") or "").strip() if not raw: return None try: return Path(raw).expanduser().resolve() except Exception: return None def append_runtime_log(message: str) -> None: text = str(message).rstrip() print(text, flush=True) path = _log_path() if path is None: return try: path.parent.mkdir(parents=True, exist_ok=True) with path.open("a", encoding="utf-8") as handle: handle.write(f"{text}\n") except Exception: pass