| 186 | self._base_dir = base_dir or (data_dir() / "traces") |
| 187 | |
| 188 | def append(self, record: dict[str, Any]) -> None: |
| 189 | try: |
| 190 | self._base_dir.mkdir(parents=True, exist_ok=True, mode=0o700) |
| 191 | day = _date_str(float(record.get("timestamp", time.time()))) |
| 192 | path = self._base_dir / f"{day}.jsonl" |
| 193 | line = json.dumps(record, default=str, ensure_ascii=False) |
| 194 | with open(path, "a", encoding="utf-8") as f: |
| 195 | f.write(line + "\n") |
| 196 | try: |
| 197 | path.chmod(0o600) |
| 198 | except Exception: |
| 199 | pass |
| 200 | except Exception: |
| 201 | pass |
| 202 | |
| 203 | def load_recent_days( |
| 204 | self, days: int, *, now: float |