nside_wefa.audit.api

Public Python API for emitting audit events.

Two surfaces:

  • log() — write an explicit event (login attempts, business actions, permission denials, anything not tied to a model save).

  • set_actor() — re-export of auditlog’s context manager so consumers can attribute events written outside a request, e.g. inside Celery tasks.

The Outcome enum is stored in LogEntry.additional_data["outcome"] so login successes, failures, and permission denials can co-exist in the same table.

Failure handling is governed by NSIDE_WEFA.AUDIT.RAISE_ON_FAILURE (default False): write errors are caught, logged as a warning, and log() returns None. Set the flag to True in tests to surface regressions.

Functions

log(action, *, actor, target, changes, ...)

Write an audit event and return the resulting log entry.

set_actor(actor[, remote_addr, remote_port])

Re-export of auditlog.context.set_actor().

Classes

Outcome(*values)

Coarse-grained outcome label stored alongside each event.

Exceptions

AuditWriteError

Raised when NSIDE_WEFA.AUDIT.RAISE_ON_FAILURE is True and a write fails.