File size: 668 Bytes
bc00a0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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