Audit Log

Pro

An audit / activity log: who changed what, when, and from what to what. The events are an interactive `sv-timeline`, newest first; the open one shows its facts (when, actor, action, resource, request context) as `sv-descriptions`, its field changes as a before → after table, each long, multi-line or structured value as an `sv-diff-viewer` line diff, and the raw record in a collapsed `sv-json-viewer`. A sensitive field is listed as changed and never printed. Filters by actor, action, resource and changed field use the shipped `sv-select-dropdown`, client-side or reported to your API; the filtered list downloads as CSV or JSON, built in the browser.

</>sv-audit-log audit logactivity logaudit trailhistorychange logdiffcompliancesecurityeventsexport

Complexity tier: Interactive The primitive bar, plus: its async states are declared — none is an answer — it has a keyboard model and restores focus, and any destructive action it offers can be undone.

import { SvAuditLogComponent } from '@styloviz-pro/display/audit-log';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

An event with field-level changes

Pro

Each change names the field and its two sides. `undefined` means the field did not exist on that side (shown "Not set"), `null` or `''` that it was empty. A string longer than 80 characters, one with a line break, or an object or array is compared as a line diff; anything else is a table row.

Filtering and paging on the server

Pro

Set `serverSide`: `entries` is shown as given and the filters only report `filtersChange`. Pass `filterOptions` from your API so a filter can offer values that are not loaded yet, and `hasMore` / `loadingMore` / `(loadMore)` to append older pages.

Export

Pro

CSV and JSON of the events currently listed (after the filters), built in the browser with no request. The CSV has one row per field change and machine column names (`event_id`, `time`, `actor`, … `field`, `before`, `after`), the spreadsheet formula guard and a BOM for Excel; sensitive values are written `[redacted]`. The JSON leaves out `raw` and keeps a sensitive change as `{ field, label, sensitive: true }`. For a full server-side export, set `[exportFormats]="[]"` and add your own button.

Your own actions

Pro

Eight actions have their own words and colours: create, update, delete, restore, permission, access, login, export. Any other `action` string works too — give its past tense as `actionLabel` and the summary reads "Billing job archived Invoice INV-1990".

When to use

  • The "History" or "Activity" tab of a record — an invoice, a customer, a member — where people need to see who changed which field.
  • A workspace security or compliance log: permission changes, sign-ins, exports, rotated secrets.
  • Use `sv-timeline` on its own for a feed with no field-level changes, and `sv-diff-viewer` on its own to compare two versions of one document.

Compare with

  • Timeline — Timeline lists any ordered events. Audit Log uses it for the event list, and adds who / what / when details, a before → after table of field changes, line diffs, the raw record, filters and export around it.
  • Diff Viewer — Diff Viewer compares two texts. Audit Log uses it for each long, multi-line or structured field of an event, and shows short values as a before → after table instead.

Async states

  • loading
  • error
  • retry
  • partial

Item identity & owned state

Item key
itemKey — set this when your rows have no id, so selection survives a reorder.

Inputs

NameTypeDefaultDescription
entriesreadonly SvAuditEntry[][]The events, any order — they are listed newest first. Rows that are not objects are skipped.
itemKeySvItemKey<SvAuditEntry>'id'Identity of an event, a property name or a function.
loadingbooleanfalseTrue while the first request is in flight — keep it false on a background refresh.
errorSvDataError | string | nullnullThe load failed. A string or an `SvDataError`; a non-retryable error hides the retry button.
filteredbooleanfalseSomething outside this component narrowed `entries` — a date range, a search box, a server-side filter — so an empty list says "No matching events", not "No activity yet". The log's own filters count without it.
hasMorebooleanfalseThere are older events to fetch: shows "Load older" under the list.
loadingMorebooleanfalseAn older page is being fetched.
filtersSvAuditLogFilters (two-way){}The active filters — two-way bindable, so a host can restore them or send them to its API.
selectedIdstring | number | null (two-way)nullThe open event's key. Null opens the newest listed event. Two-way bindable.
serverSidebooleanfalseYour API applies the filters: `entries` is shown as given and the filters only report `filtersChange`. Pass `filterOptions` too, or each filter can only offer the values already loaded.
filterOptionsSvAuditFilterOptionsInput{}Choices per filter, replacing the ones derived from `entries`.
filterKeysreadonly SvAuditFilterKey[]['actor', 'action', 'target', 'field']Which filters to show, in order. `[]` hides the filter bar.
exportFormatsreadonly SvAuditExportFormat[]['csv', 'json']Download buttons, in order. The file holds the events currently listed (filtered), built in the browser; sensitive values are redacted. `[]` hides them.
exportFileNamestring'audit-log'File name without the extension; characters file systems reject become `-`.
headingstring''The log's title. `''` uses the "Audit log" label.
headingLevelSvAuditLogHeadingLevel2Heading level of the title — match your page outline.
localestringsvLocale()BCP-47 locale for dates and lists.
timeZonestring | nullnullIANA time zone the times are shown in, e.g. `'UTC'`. Null, or a zone `Intl` rejects, uses the viewer's.
diffViewSvDiffViewerView'unified'Unified or split layout for the line diffs of long values.
showRawbooleantrueShow the event's raw record in a collapsed JSON viewer.
rawRedactJsonRedactor | nullnullHides values in the raw record (passed to `sv-json-viewer`'s `redact`) — e.g. `secretKeyRedactor`.
collapseAfternumber0Show this many events, then "Show N more" (the timeline's own disclosure). `0` shows all.
labelsPartial<SvAuditLogLabels>{}Per-instance text, merged over the registry's `displayPro` labels.

Outputs

EventPayload typeDescription
retryvoidThe error state's retry button was pressed — re-run the request.
loadMorevoid"Load older" was pressed — append the next page to `entries`.
entrySelectSvAuditEntryAn event was opened from the list.
exportedSvAuditExportEventA file was downloaded.
filtersChangeSvAuditLogFiltersEmits the new `filters` whenever it changes — the output half of `[(filters)]`.
selectedIdChangestring | number | nullEmits the new `selectedId` whenever it changes — the output half of `[(selectedId)]`.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Pro

Bound to the names this component actually exposes.

Host class

Pro

Drive the three async inputs from your own fetch.

  • This component does not emit a query, so it renders what you give it. Call `load()` on your own trigger and bind `entries`, `loading` and `error`.
  • Set `filtered` when a search or filter is active. It is the difference between "you have no orders" and "no orders match this filter" — telling a customer with 4,000 orders the first one reads as a bug.
  • `hasMore` and `loadMore` drive incremental paging: set `hasMore` from the response, and append the next page when `loadMore` fires.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • Colours: create / restore paint `accent`, update `info`, delete and failures `danger`, permission changes `warning`, export the brand accent, access and sign-in `gray` — the timeline's tokens, so a theme that remaps them recolours the dots.
  • `filterKeys` chooses which of the four filters show and in what order (`[]` hides the bar); `filterOptions` replaces the derived choices per filter.
  • `diffView` (`unified` / `split`) sets the layout of the line diffs; `showRaw` hides the raw record; `collapseAfter` folds a long list behind "Show N more".
  • The list and the details sit side by side once the component is about 48rem wide (a container query, not the viewport), and stack below that — so it fits a drawer as well as a page.
  • Every string comes from the `displayPro` labels (`audit*` keys) in 12 language packs — `provideSvLabels(SV_DISPLAY_PRO_LABELS_DE)` or the per-instance `labels` input. CSV column names stay machine names in every language.
  • `svAuditFilterEntries`, `svAuditFilterOptions`, `svAuditChangeKind`, `svAuditEntriesToCsv`, `svAuditEntriesToJson` and `svAuditStableJson` are exported for a server, a digest or a test.

Best practices

  • Do: Mark secrets and personal data `sensitive: true`. The change is listed, the values are never rendered and are redacted in both exports — but they are still in your payload, so leave them out server-side when the viewer may not see them at all.
  • Do: Give each change a human `label`; `field` stays the machine name the field filter and the CSV use.
  • Do: Pass `timeZone` when your users compare times with a server log, so "09:42" means the same moment in both.
  • Do: Pass `rawRedact` (e.g. `secretKeyRedactor` from `@styloviz/display`) when `raw` is your backend's own record — it can hold a token the `changes` were careful to hide.
  • Don't: Don't set `loading` while re-querying after a filter change. It swaps the log, and the filter just used, for a skeleton; keep the old page up until the new one arrives.
  • Don't: Don't rely on the export for a complete server-side audit. It writes what is loaded and listed; a log you page from the server needs its own export endpoint.
  • Tip: Bind `[(filters)]` and `[(selectedId)]` to the URL so a link opens the same event with the same filters.

Accessibility

  • Events are the shipped interactive timeline: each is a focusable button with `aria-pressed` for the open one, Enter / Space opens it, and the list is named ("Audit events"). Action and failure are words in a badge, never colour alone.
  • The open event is a labelled region with a real heading at `headingLevel + 1`; its facts are a description list (`<dl>`), and its time is a `<time datetime>`.
  • Field changes are a `<table>` with a caption and `scope="col"` / `scope="row"` headers; before and after are `<del>` / `<ins>` under "Before" / "After" column headers, and missing, empty and hidden values are words ("Not set", "Empty", "Hidden"), not blank cells. The table scrolls inside a focusable, named region on a narrow screen and prints in full.
  • Filters are the shipped `sv-select-dropdown` combobox, each with a visible label, grouped and named ("Filter audit events"). An export is announced in a polite status region ("Exported 6 events as CSV.").
  • Loading, error and both empties use the kit's shells: the error is a `role="alert"` with Try again, and "No matching events" offers Clear filters.

Feedback on Audit Log

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.