Activity Log & Audit Trail Timeline (pkg/activitylog)
GoFilament features a comprehensive, production-grade Activity Log & Audit Trail package for tracking entity history, user actions, system events, and changesets:
1. Fluent Activity Logger#
// Log custom actions anywhere in your application
activitylog.Log("Customer credit limit increased").
Subject("Customer", "42").
Causer("Admin", "1", "Alice Admin").
Event("updated").
WithDiff(
map[string]any{"credit_limit": 5000},
map[string]any{"credit_limit": 15000},
).
Property("approved_by_finance", true).
IP(c.ClientIP()).
Save(c.Request.Context())
2. Automated Resource Auditing (Zero Boilerplate)#
Automatically track all Create, Update, and Delete actions with pre/post changeset diffs and authenticated causers:
userResource := filament.NewResource[*ent.User]("users")
// Automatically logs all CRUD actions on the resource (call it after the On* handlers)
activitylog.EnableAuditLog(userResource)
// Or via the top-level helper:
gofilament.EnableAuditLog(userResource)
// With options: never store these fields' values
activitylog.EnableAuditLogWith(userResource, activitylog.AuditOptions{Except: []string{"ssn"}})
- Record history: the view and edit pages get a History section (who,
when, each changed field before → after), the API serves it at
GET /admin/api/resources/:slug/:id/history, and the Flutter record form has a History button. It is shown to users who can view the record;resource.HistoryVisible(fn)narrows that,AuditOptions.NoHistoryturns it off. - Only fields that really changed are recorded (form fields are matched to the
record’s keys, so
FullNameandfull_nameare the same field); an update that changes nothing is not logged. Inline cell edits and bulk deletes are logged too. - Password fields, fields named like
*password*,*secret*,*token*andAuditOptions.Exceptare stored as “(hidden)” / “(changed)”, never their values. - In
OnCreate, callfilament.SetCreatedID(ctx, id)so the “created” entry belongs to the new record.
3. Vertical Audit Timeline & Infolist Component#
Embed visual audit timelines with interactive diff inspectors directly inside resource View schemas:
userResource.Infolist(func(infolist *infolists.Infolist) *infolists.Infolist {
return infolist.Schema(
infolists.Section("User Details").Schema(
infolists.TextEntry("name"),
infolists.TextEntry("email"),
),
infolists.Section("Audit Trail & History").Schema(
activitylog.TimelineEntry("activities").
Title("Recent Activity").
Filterable(true). // Live client-side event filtering and search
CollapsibleDiffs(true), // Expandable changeset diff accordions
),
)
})
- Interactive Changeset Diff Inspector: Expands before/after comparison tables showing field changes with strikethrough red pills for previous values and green pills for updated values.
- Continuous Connected Timeline Spine: Visual status node circles with event icons (plus for created, pencil for updated, trash for deleted, check for approved, etc.).
- Actor Badges & Fallbacks: Renders actor avatars or automatic initials badges (
AAfor Alice Admin) with hoverable exact timestamps and relative time representation (“just now”, “15 minutes ago”, “yesterday”). - Standalone Audit Resource: Mount
gofilament.NewActivityResource()(oractivitylog.NewActivityResource()) to provide administrators with a complete audit browsing and search interface in the panel navigation.