Skip to main content

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 formatterJSONLLogFormatter renders 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) and RotatingFileHandler (file).
  • Loki examples — ships Grafana Alloy / Loki / Grafana templates and the sec-audit-loki-init generator.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sec_audit_logging-0.1.0a1.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sec_audit_logging-0.1.0a1-py3-none-any.whl (26.2 kB view details)

Uploaded Python 3

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

Hashes for sec_audit_logging-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 a00b175a4af8780743b42260dd068253ec0507d19415430129c2d0d09e85ca48
MD5 64e9470ae7459930d8c3a003d9aeb8ba
BLAKE2b-256 830f40ba8e3de21426dd0402b5cd78fe1ce944f7ed04283c223dd5f1aafaade1

See more details on using hashes here.

File details

Details for the file sec_audit_logging-0.1.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for sec_audit_logging-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 15a280d1fb647523ffb50a85343a4ae01031580d7ee5e852911c1688df180532
MD5 e3f409cfce9d77bb533749777c4f9b1d
BLAKE2b-256 6f24a691b2f6e8ac51e063748f0b4f8bda143c3956eccd1fe0b675d17c506901

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page