# Audit log
Source: https://sovaria.in/docs/audit-logs

What the audit log records, how to search it, how long it is kept, how to check it hasn't been altered and how it differs from request logs and version history.

The audit log is the record of **who changed what**: sign-ins, policy and table changes, deletions, restores and the rest of the events below, with the actor, the time and where it came from. Open it under **Logs & Audit › Audit**.

| Record | Answers | Where |
|---|---|---|
| **Audit log** (this page) | Who changed what, and when? | Logs & Audit › Audit |
| Request logs | Which requests came in, with status and timing? | Observability, Logs & Audit — [Logs and log drains](https://sovaria.in/docs/logs-and-log-drains) |
| Version history | What did the schema, policies or functions look like before, and can I go back? | [Version history: see, undo and restore changes](https://sovaria.in/docs/version-history) |
| Migration history | Which migrations ran, in which order? | [Migrations](https://sovaria.in/docs/migrations) |

## What is recorded

| Area | Events |
|---|---|
| Sign-in | `auth.login`, `auth.register`, `auth.logout` |
| Organizations and projects | `node.created`, `node.updated`, `node.deleted`; memberships as `edge.created`, `edge.deleted` |
| Access policies | `policy.created`, `policy.updated`, `policy.deleted`, `policy.evaluated` |
| Tables | `table.created`, `table.dropped`; row changes `row.inserted`, `row.updated`, `row.deleted` where recorded |
| Version history | `timeline.spawned`, `timeline.jumped`, `timeline.deleted`, `snapshot.created`, `snapshot.restored` |

Each entry has the event type, the part of Sovaria that recorded it (`service`), the actor, the time and the details of the change. Security-relevant account events (new devices, password and two-factor changes) are also emailed to the person concerned.

## Search and export

- **Focus** narrows to errors, security, policy, functions or data events; **Source** and **Event type** filter further.
- Select entries (Shift-click for a range) to **Copy as JSON** or **Download** them.
- Stream logs to your own tools continuously with log drains — [Logs and log drains](https://sovaria.in/docs/logs-and-log-drains).

### Export the whole log

**Export CSV** on the Audit page exports the current project. For the whole organization (what auditors ask for), owners and admins use **Organization › Compliance › Export audit log**, the CLI or the API. An export covers your plan's retention window, oldest entry first, with each entry's hashes so the chain can be checked offline. Every export is itself written to the log as `audit.exported` (who, which filters, how many rows).

| Filter | What it keeps |
|---|---|
| `since`, `until` | A time window (ISO 8601). A value that isn't a timestamp is refused with `400`. |
| `event_type`, `event_type_prefix`, `actor_id`, `source`, `resource_id`, `project_id`, `env_id` | One kind of event, one person, one service, one resource, one project or environment. |
| `phi_only=true` | Only requests to projects marked as holding PHI: the HIPAA access log ([HIPAA mode and PHI projects](https://sovaria.in/docs/hipaa#phi-log)). |
| `staff_access_only=true` | Only Sovaria staff viewing your data under a time-limited support grant. |
| `after_seq` | One call returns at most 100,000 entries. A longer export answers with `X-Sovaria-Export-Truncated: true` and `X-Sovaria-Export-Next-After-Seq`: ask again with `after_seq` set to it. The console and `sov compliance audit-log` fetch every page into one file. |

CLI:
```bash
sov compliance audit-log -o audit.csv                         # whole organization, CSV
sov compliance audit-log --format json --since 2026-10-01T00:00:00Z -o audit.json
sov audit verify                                               # check the chain
```

JavaScript:
```js
const recent = await sovaria.audit.list({ event_type: 'policy.updated', limit: 50 })
const check = await sovaria.audit.verify()   // { chain_valid, … }
const { count } = await sovaria.audit.count()
```

cURL:
```bash
curl -s "https://api.sovaria.in/api/v1/audit/export?format=csv&since=2026-10-01T00:00:00Z" \
  -H "Authorization: Bearer $TOKEN" -H "X-Sovaria-Org-ID: $ORG_ID" -o audit.csv
```

### With a project API key

A project API key (the service-role key, a custom key, or a function's own key) reads and exports **its own project's** entries only: asking for another project (`project_id`) answers `403`, and without a filter it gets just its project. Keys can add their own events (`POST /api/v1/audit/`, recorded under the key) but never hide or restore entries (`403`): what the log shows is an owner's or admin's decision, made from the console. For the organization's whole log, use a member's session (owners and admins, or anyone with `logs.read`).

## Tamper evidence

Entries are chained: each one includes a hash of the one before, so changing or removing an entry breaks the chain. **Verify** on the Audit page (or `GET /api/v1/audit/verify`) recomputes the chain and reports whether it is intact.

cURL:
```bash
curl -s "https://<project-ref>.sovarias.in/api/v1/audit/verify" -H "Authorization: Bearer $TOKEN"
curl -s "https://<project-ref>.sovarias.in/api/v1/audit/count" -H "Authorization: Bearer $TOKEN"
```

## How long entries are kept

By plan; with HIPAA mode on, audit entries are kept for six years whatever the plan ([HIPAA mode and PHI projects](https://sovaria.in/docs/hipaa)).

|  | Free | Pro | Ultra | Team | Enterprise |
|---|---|---|---|---|---|
| Audit log retention | 1 day | 7 days | 30 days | 365 days | 365 days |
| Audit log retention while HIPAA mode is on | 2190 days | 2190 days | 2190 days | 2190 days | 2190 days |

## Who can see it

Members with `logs.read` — every built-in role, including Viewer ([Organizations, members and roles](https://sovaria.in/docs/organizations)). App users never see it.
