Framework-free structured audit logging: OTel JSONL emission, scrubbing, formatters, file handlers, and Loki examples
Project description
sec-audit-logging
Framework-free structured audit logging for the sec-audit
core. Emits OpenTelemetry LogRecord-shaped
JSONL — one JSON object per line — ready for Loki/Grafana, Wazuh, or any SIEM.
This package is Django-free. For Django integration use
django-sec-audit,
which depends on this package.
Features
- OTel JSONL formatter —
JSONLLogFormatterrenders the OTel LogRecord envelope (timestamp,severity_*,resource,attributes, …) as a single JSON line. - Scrubbing — sensitive keys/value patterns are redacted before emission; cycle- and shared-reference-safe.
- Projection limits — bounds nesting depth, string sizes, and record bytes with a graceful multi-tier fallback so a single oversized record never breaks the stream.
- Filter / enricher pipeline — pluggable callables run before emission.
- Handlers — works with stdlib
StreamHandler(stdout) andRotatingFileHandler(file). - Loki examples — ships Grafana Alloy / Loki / Grafana templates and the
sec-audit-loki-initgenerator.
Install
pip install sec-audit-logging
Emitting a record
External packages provide the final primitive logging attributes:
import logging
from sec_audit.logging import emit_log
emit_log(
logging.getLogger('sec_audit'),
'payment.checked',
{'event_type': 'payment.checked', 'schema_version': '1.0', 'payment_id': 'pay-1'},
logging.INFO,
)
Builders return new dicts (immutable); scrubbers return new dicts with sensitive values redacted.
Loki / Grafana stack generator
The bundled console script copies a ready-to-run monitoring stack (Grafana Alloy → Loki → Grafana) from the package's canonical templates:
sec-audit-loki-init monitoring \
--app-label myapp \
--environment prod \
--audit-log-path ../logs/sec-audit.jsonl
See the Loki setup guide for an end-to-end walkthrough.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sec_audit_logging-0.1.0a1.tar.gz.
File metadata
- Download URL: sec_audit_logging-0.1.0a1.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a00b175a4af8780743b42260dd068253ec0507d19415430129c2d0d09e85ca48
|
|
| MD5 |
64e9470ae7459930d8c3a003d9aeb8ba
|
|
| BLAKE2b-256 |
830f40ba8e3de21426dd0402b5cd78fe1ce944f7ed04283c223dd5f1aafaade1
|
File details
Details for the file sec_audit_logging-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: sec_audit_logging-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 26.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15a280d1fb647523ffb50a85343a4ae01031580d7ee5e852911c1688df180532
|
|
| MD5 |
e3f409cfce9d77bb533749777c4f9b1d
|
|
| BLAKE2b-256 |
6f24a691b2f6e8ac51e063748f0b4f8bda143c3956eccd1fe0b675d17c506901
|