API Reference audit_trail v#0.1.1
Copy MarkdownModules
Reusable structured audit logging, DB change tracking, and crash reporting.
Behaviour for AuditTrail storage backends.
Storage adapter that ships logs to Grafana Loki via HTTP.
Storage adapter that persists audit logs to a PostgreSQL table.
Raw SMTP adapter using Swoosh's SMTP adapter directly. Does not require a host-app Mailer module — reads SMTP config from AuditTrail config.
Swoosh mailer adapter. Requires the host app to have Swoosh configured.
In-memory storage adapter for tests. Accumulates every pushed log in an ETS table instead of shipping it anywhere, so a test suite can assert on what got logged without a running Loki/Postgres.
Storage adapter for TimescaleDB — PostgreSQL with automatic time partitioning.
Plug for declarative controller-level audit logging.
OTP :logger handler that intercepts error/crash events and routes them through AuditTrail.Deduplicator → AuditTrail.Notifier.
Computes field-level diffs from Ecto changesets.
Declarative audit logging for LiveView handle_event/3, mirroring
AuditTrail.ControllerAudit's write/read config style for controllers.
Phoenix plug that sets the actor context and logs every HTTP request.
Query audit logs from Loki.
Add to your Ecto.Repo (after use Ecto.Repo) to enable automatic
schema-level change tracking for any schema that uses AuditTrail.Schema.
Runs on every payload in AuditTrail.Buffer right before it ships
— the one choke point every entry point (emit/2, monitor/4, schema-level
Diff, ControllerAudit) funnels through. Besides making values
JSON-safe, it redacts any map value whose key matches
AuditTrail.Config.sensitive_fields/0 (case-insensitively, atom or string
keys, at any nesting depth) — so a sensitive field slipping into a
track: :all schema diff, or into monitor/emit's original_record:/
params: diffing, still gets caught here even if the call site forgot to
filter it out itself. ControllerAudit still does its own upfront
Map.drop/2 for the same field list — this is the backstop for
everything else.
Marks an Ecto schema for automatic field-level change tracking.
Drop-in wrappers for Task that propagate the actor context to child processes.
Process-dictionary store for the current tenant/org id, mirroring
AuditTrail.ActorStore. Set once per request/job with AuditTrail.set_tenant/1;
every subsequent emit/monitor/schema-tracked Repo call in the same
process is tagged with it automatically.
Test helpers for asserting on audit events, meant to be used together
with AuditTrail.Adapters.Test (see its moduledoc for setup).
Mix Tasks
Generates an Ecto migration for the audit_logs table.