|
Option C Tools
|
Public Member Functions | |
| None | __init__ (self, Path project_root) |
| None | write (self, AuditRecord record) |
| Path|None | current_path (self) |
Protected Member Functions | |
| None | _ensure_logs_dir (self) |
| Path | _new_filename (self) |
| int | _current_file_size (self) |
| None | _rotate_if_needed (self) |
| list[Path] | _list_existing_files (self) |
| None | _prune_old_files (self) |
Protected Attributes | |
| Path | _project_root = Path(project_root) |
| Path | _logs_dir = resolve_logs_dir(self._project_root) |
| Path|None | _current_path = None |
Append-only rotating JSONL logger for ``oct git`` commands.
One instance corresponds to one project root. The constructor does
not open a file — the first :meth:`write` call lazily materialises
the ``logs/`` directory and the current audit file. This lets a
command that never reaches the write stage (e.g. a CLI parse error)
leave no side-effects on disk.
Rotation strategy
-----------------
- **Size rotation:** before each write, if the current file is at or
above :data:`AUDIT_MAX_SIZE_BYTES`, close it and open a new
timestamped file. The rotating write itself goes into the new
file, not the old one.
- **Count pruning:** after any rotation, if the number of
``git-audit-*.jsonl`` files in the logs directory exceeds
:data:`AUDIT_MAX_FILES`, delete the oldest (lexical order) until
the count is within the limit.
Error handling
--------------
Any IO error during :meth:`write` — creating the directory, opening
the file, serialising the record, writing the line, or rotating —
is caught and logged via ``_dbg("GIT", ..., 1)``. The method never
raises; audit logging is best-effort observability and must not
mask command failures.
| None oct.git.audit.AuditLogger.__init__ | ( | self, | |
| Path | project_root ) |
|
protected |
|
protected |
|
protected |
|
protected |
Return a fresh ``git-audit-YYYYMMDD-HHMMSS.jsonl`` path. Uses the current UTC timestamp. If the resulting filename already exists (unlikely but possible at sub-second rotation or in a fast loop), disambiguate by appending a monotonic suffix ``-<counter>`` so no two rotations collide.
Definition at line 211 of file audit.py.
|
protected |
Delete the oldest files until count <= :data:`AUDIT_MAX_FILES`. Deletion is best-effort: an ``OSError`` from a concurrent reader holding a handle on Windows is logged but not re-raised.
Definition at line 271 of file audit.py.
|
protected |
Open a fresh file if the current one is missing or full. Called at the top of :meth:`write`. After opening a new file, delegates to :meth:`_prune_old_files` so count-based rotation runs at the same moment size-based rotation does (cheapest common path).
Definition at line 240 of file audit.py.
| Path | None oct.git.audit.AuditLogger.current_path | ( | self | ) |
| None oct.git.audit.AuditLogger.write | ( | self, | |
| AuditRecord | record ) |
|
protected |
|
protected |
|
protected |