# Read the Audit Log in the Admin

> Explore the audit log on the admin's Audit log page: filters, paging, what it shows and how it reads.

*Canonical: https://makerkit.dev/docs/void-cloudflare/audit/reading-the-log*

---

Platform admins who hold the `audit:list` permission (the `admin` role does) get an **Audit log** page in the admin navigation (`/admin/audit`). A user's page (`/admin/users/<id>`) and an organization's page (`/admin/organizations/<id>`) have a **View audit log** button that opens it filtered to them. Everyone else gets no link, no button, and a 404 for the page.

## The Audit Log Page

The page uses the shared compact admin header: title and description together beside the sidebar toggle, with filters below.

With no filter, `/admin/audit` shows the latest events across the platform. The shared filter toolbar updates the URL as selections change, so a filtered view can be reloaded or shared with another admin:

- **Add filter → User** or **Organization**, one at a time. Search names/emails or names/slugs and pick a result. Discovery needs `user:list` or `organizations:list`. Selecting one replaces the other. Bookmarks retain IDs; unavailable/deleted/restricted names use a generic removable chip.
- **Created**, a UTC range; the last day is included. Choose Today/Last 7/Last 30 days or a custom range, then **Apply range**. Click a chip to edit, × to remove, or **Clear filters** to reset.
- **Older events**, under the list, opens the next 50. A new filter starts again from the newest.

A malformed id, a date that isn't one, both ids at once or a broken page link shows what is wrong above the list and reads nothing.

## What It Shows

- **A user:** events about the user, by the user, or while an admin was signed in as the user.
- **An organization:** events scoped to the organization or carrying its id (members, invitations, renames, billing).
- Newest first, 50 at a time, from the last 90 days. Each row has the time (UTC), the action, its severity, who did it (linked to their admin page), the target and the details (plan names, roles).
- **Best effort.** Analytics Engine can take a minute to show a new event and samples under heavy traffic. Treat the page as an investigation aid, not a complete record.

## Turn It On

Nothing to set up. Every deploy (`vp run deploy`, locally or in Workers Builds) binds Cloudflare's [Analytics SQL binding](https://developers.cloudflare.com/analytics/sql-api/workers-binding/) in `void.config.ts` (`analytics`), so the Worker reads its own dataset with no API token and no account id. It needs Wrangler 4.145 or later and Workers Analytics Engine on the account. The binding is in beta.

Reading works only once deployed. The binding has no local simulator: bound locally, Wrangler would connect to Cloudflare and ask you to log in. So `pnpm dev` and `vp preview` (the e2e suite, CI) leave it out and need no Cloudflare login; events are logged, not stored, and the page says reading is not available. The deploy script sets `KIT_DEPLOY=1`, which is what makes `void.config.ts` add the binding: a `void deploy` run directly deploys without it. After a local deploy, rebuild before a bare `vp preview` (`vp run preview` does), or the old build asks for the login again.

## When It Fails

The page says the log can't be read right now, and the filters still load. The admin log records `admin.audit_read_failed` with a code (`network`, `rejected` or `bad_answer`, or `threw` for an error before Cloudflare answered) and the ids, never the token. `rejected` means Cloudflare refused the query; `network` is a timeout or a retryable error.

## How It Reads

The page runs one query through the Analytics SQL binding against `events.analyticsEngine."audit_events"`: `reader.search` in `@kit/audit/server`, which takes an optional user or organization, a `from`/`to` range and a cursor, and answers 50 events with the cursor of the next older page. Ids and times are bound parameters; the kit also only accepts ids made of letters, digits, `_` and `-` (up to 64), and refuses those, invalid dates and malformed cursors before any query. Reading the log is not itself recorded.

The cursor is the last event's second plus how many events of that second were already shown, so events written in the same second are not skipped or repeated across pages, and new events don't shift older pages. Best effort, like the rest of the page: a row Analytics Engine stores late, in a second already being paged, can shift that second by one; sampled rows are not shown. Past 10,000 events in one second the paging stops, as on the last page.
