Jsonl audit logger best effort
Skill kjuhwa/skills-hub/skills/observability/jsonl-audit-logger-best-effort
Append-only JSONL audit log for security-relevant events that swallows OS errors so logging failures never crash the calling code, and reads back the last N entries on demand.From its SKILL.md
npx -y skills add kjuhwa/skills-hub --skill jsonl-audit-logger-best-effortAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
3.0 KB, 569 tokens by cl100k_base, as published. Nobody here has run it
Best-Effort JSONL Audit Logger
When to use
You need a tamper-evident-ish audit trail for security events (guardrail matches, key resolutions, redactions) that lives on the user's local disk, but a disk-full or permission error must NOT propagate up and crash the LLM call.
How it works
- One file (default
~/.opensre/guardrail_audit.jsonl). log()writes one JSON object per line with UTC timestamp, rule name, action, and a 40-char preview of the matched text.- All writes wrapped in
try/except OSErrorand just log a warning on failure. read_entries(limit=100)returns the last N parsed entries, skipping malformed lines.
Example
import json, logging
from datetime import UTC, datetime
from pathlib import Path
class AuditLogger:
def __init__(self, path: Path | None = None) -> None:
self._path = path or Path.home() / ".opensre" / "guardrail_audit.jsonl"
def log(self, *, rule_name: str, action: str,
matched_text_preview: str, context: str = "") -> None:
preview = matched_text_preview[:40]
entry = {
"timestamp": datetime.now(UTC).isoformat(),
"rule_name": rule_name, "action": action,
"matched_text_preview": preview, "context": context,
}
try:
self._path.parent.mkdir(parents=True, exist_ok=True)
with self._path.open("a", encoding="utf-8") as fh:
fh.write(json.dumps(entry) + "\n")
except OSError:
logging.getLogger(__name__).warning("Failed to write audit to %s", self._path)
def read_entries(self, *, limit: int = 100) -> list[dict]:
if not self._path.exists(): return []
try:
lines = self._path.read_text(encoding="utf-8").strip().splitlines()
except OSError:
return []
out = []
for line in lines[-limit:]:
try: out.append(json.loads(line))
except json.JSONDecodeError: continue
return out
Gotchas
- Always preview-truncate the matched text — never write full secrets to the audit log; the audit defeats its own purpose if the file becomes a leaked-secrets goldmine.
- Use
Path.home() / ".myapp" / ...so the audit lives outside the project tree and survivesgit clean. - For high-throughput scenarios, batch-buffer writes and flush periodically; this implementation is simple enough for sub-100-event/sec workloads.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.