from __future__ import annotations import json import time from pathlib import Path class Tracker: def __init__(self, path: Path): self.path = Path(path); self.path.parent.mkdir(parents=True, exist_ok=True) self.t0 = time.time() def log(self, **kw) -> None: kw["elapsed_s"] = round(time.time() - self.t0, 1) with open(self.path, "a") as fh: fh.write(json.dumps(kw, default=float) + "\n")