Documentation
¶
Overview ¶
Package auditlog is a PocketBase plugin that records an audit trail of the changes made to your collections.
Register it against an app instance before calling app.Start:
app := pocketbase.New()
if err := auditlog.Register(app); err != nil {
log.Fatal(err)
}
Or use MustRegister to panic on failure instead of handling the error.
Behaviour ¶
Every collection is audited by default. On every boot the plugin applies its pending schema migrations, which on first boot create the "_auditLogs" and "_auditLogSettings" collections. It then seeds the settings row from the Option values passed to Register (or their defaults) and installs the hooks, crons, and routes that keep the audit trail running.
Migrations are tracked in the plugin's own "_auditLogMigrations" table, separate from PocketBase's "_migrations", so the host application's "migrate" commands never interfere with the plugin's schema history. After first boot, the values stored in "_auditLogSettings" — editable from the plugin's settings modal in the admin UI — are authoritative, and the registration options only seeded that initial row.
Only mutations that go through the REST API (create/update/delete request hooks) are recorded; changes made programmatically from Go (app.Save, cron jobs, migrations, ...) bypass those hooks and are not logged. Audit writes are also best effort and not transactionally tied to the change they describe: if writing the entry fails, the error is logged and the original operation still succeeds, so a change can occur without a corresponding audit log entry. Do not rely on this plugin as a guaranteed, tamper-proof record.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustRegister ¶
MustRegister registers the audit plugin to the provided app instance and panics on error.
Types ¶
type Option ¶
type Option func(*config)
Option configures the audit plugin.
func WithInitialExcludedCollections ¶
WithInitialExcludedCollections sets the collections (by name or id) excluded from auditing when the "_auditLogSettings" row is seeded on first boot only. Names that don't resolve to an existing collection at that point are skipped. After the first boot the value stored in the DB is authoritative and this is ignored.
func WithInitialRetentionDays ¶
WithInitialRetentionDays sets the retention window (in days) used to seed the "_auditLogSettings" row on first boot only. 0 means "keep forever". After the first boot the value stored in the DB is authoritative and this is ignored.