LogarithmLive demo.
This is the settings page of a made-up SaaS app. Every change you make is recorded with the same code as the npm package and shows up in the activity view next to it, the way your customers' admins would see it.
Everything runs in this page and is kept in memory. Nothing you enter is sent anywhere, and a reload starts over.
Try it
Change somethingand see who did what.
Switch the person you act as, edit the project, invite or remove members, rotate the API key. Open Details on an entry to see the field changes. The SMTP password is stored as [redacted], never in clear text.
Acme Cloud · Project settings
- ben@acme.example
- lea@acme.example
API key: sk_live_…9c1e
Click it five times to see what Logarithm Pro's anomaly alert would catch.
Activity
<ActivityFeed>: the latest entries as a dashboard widget.
In your app
Three piecesRecord, serve, show.
Record events where things change, expose them through a route that checks access and scopes to the tenant, and drop the view into your admin area.
// app/projects/actions.ts
await audit.with({ tenantId: org.id, actor: { id: user.id, name: user.name } }).record({
action: "project.updated",
targets: [{ type: "project", id: project.id, name: project.name }],
before: project,
after: updated,
})// app/api/audit/route.ts
import { createAuditHandler } from "@sweberdev/logarithm"
export const GET = createAuditHandler({
log: audit,
async authorize() {
const session = await getSession()
return session?.role === "admin" ? { tenantId: session.orgId } : null
},
})// app/settings/activity/page.tsx
"use client"
import { AuditLog } from "@sweberdev/logarithm-react"
import "@sweberdev/logarithm-react/styles.css"
export default function Activity() {
return <AuditLog endpoint="/api/audit" locale="de-CH" />
}// app/dashboard/page.tsx
const logins = await audit.count({ action: "user.signed_in", groupBy: "day" })
// [{ key: "2026-10-05", count: 412 }, { key: "2026-10-06", count: 388 }]Free 2.0
Outcome, correlation id and standard formatsLogarithm, free.
Logarithm 2.0 records how every action ended and ties events of one request together, and it maps events to CloudEvents and OpenTelemetry. Large Postgres tables can now be partitioned, all in the MIT package.
Outcome: record what was refused
Every event now says how the action ended: success, failure or denied. Denied attempts are often the first thing an auditor asks about, and you can filter by result.
Record a denied export and filter by outcome
const log = audit.with({ tenantId: "acme", actor: { id: "u_42" }, correlationId: "req-7f3a" })
await log.record({ action: "project.updated", targets: [{ type: "project", id: "p1" }] })
await log.record({
action: "export.created",
targets: [{ type: "project", id: "p1" }],
outcome: "denied",
metadata: { reason: "missing permission export:create" },
})
const { events } = await audit.query({ outcome: "denied" })
const same = await audit.query({ correlationId: "req-7f3a" })Real output (SQLite, Node 22)
1 export.created denied req-7f3a
[ 'export.created denied', 'project.updated success' ]Correlation id across a request
Set one correlationId per request, job or trace and every event of that operation carries it. Query by it to see everything one request did.
Same example: both events share req-7f3a
audit.with({ correlationId })
audit.query({ correlationId })
// over HTTP: ?correlation=req-7f3aCloudEvents 1.0 export
Turn any event into a CloudEvents envelope for brokers like EventBridge, Event Grid or Knative. The function is pure, so you choose the transport.
toCloudEvent
import { toCloudEvent } from "@sweberdev/logarithm"
const ce = toCloudEvent(events[0], {
source: "https://app.example.ch/audit",
typePrefix: "ch.example.audit",
})Real output (data block trimmed)
{
"specversion": "1.0",
"id": "01M4V0498XFTZZ9DMR9VTW2G7Y",
"source": "https://app.example.ch/audit",
"type": "ch.example.audit.project.updated",
"time": "2026-10-13T16:04:32.668Z",
"datacontenttype": "application/json",
"data": { ... },
"subject": "project/p1",
"tenantid": "acme",
"outcome": "failure",
"correlationid": "req-7f3a"
}OpenTelemetry logs
Send events to any OTLP backend such as the OpenTelemetry Collector, Grafana, Datadog or Honeycomb. Severity follows the outcome, and a 32-hex correlation id becomes the trace id.
toOtlpLogs
import { toOtlpLogs } from "@sweberdev/logarithm"
const body = toOtlpLogs(events, { serviceName: "billing" })
// POST body as JSON to http://otel-collector:4318/v1/logsReal output (denied event: severity, body, attributes)
WARN export.created
event.name = export.created
enduser.id = u_42
logarithm.event.id = 01M4V049ATC335RY4NRJ6S12NE
logarithm.outcome = denied
logarithm.actor.type = user
logarithm.correlation_id = req-7f3aPostgres partitioning
Very large Postgres audit tables can be partitioned by month or year, so time-range queries stay fast and removing old months is a metadata operation.
Create a partitioned table
import { migratePostgres, ensurePartitions } from "@sweberdev/logarithm/postgres"
await migratePostgres({ client: pool, partitioned: true })
await ensurePartitions({ client: pool, from: new Date(), to: "2027-03-31" })Real output of postgresSchema({ partitioned: true }), first lines
CREATE TABLE IF NOT EXISTS "audit_events" (
id text COLLATE "C" NOT NULL,
occurred_at timestamptz NOT NULL,
tenant_id text,
action text NOT NULL,
actor_id text NOT NULL,
actor jsonb NOT NULL,
targets jsonb NOT NULL DEFAULT '[]',
changes jsonb NOT NULL DEFAULT '[]',
context jsonb NOT NULL DEFAULT '{}',
metadata jsonb NOT NULL DEFAULT '{}',
outcome text,
correlation_id text,
search text NOT NULL DEFAULT '',
PRIMARY KEY (occurred_at, id)
) PARTITION BY RANGE (occurred_at);
CREATE TABLE IF NOT EXISTS "audit_events_default" PARTITION OF "audit_events" DEFAULT;Also new in free 2.0: the React ObjectHistory component (history of one object with a diff per change) and a result filter in AuditLog. Existing tables upgrade in place with migrate*; Node 22 or newer is required.
Read the docsPro 2.1.0
Run it as a serviceLogarithm Pro.
Pro 2.1.0 adds a ready-to-run admin server, so your customers' admins get the audit log without you building a view. It also brings new alert rules and e-mail alerts.
Admin server in one containerBeta
Search, filter, export and view the audit log of a tenant in a ready-made admin view. Runs on Postgres, MySQL/MariaDB or SQLite and is configured with environment variables only.
Docker
docker run -p 3000:3000 \
-e LOGARITHM_DATABASE_URL=postgres://user:pass@db:5432/app \
-e LOGARITHM_ADMIN_TOKENS="acme=<long random token>,globex=<another one>" \
-e LOGARITHM_INGEST_KEY=<long random key> \
-e LOGARITHM_SLACK_WEBHOOK=https://hooks.slack.com/services/... \
ghcr.io/weber-development/logarithm-server:latestWrite events from any language
Apps in PHP, Python, Java or .NET send events over HTTP. The ingest key decides the tenant, and you can send up to 100 events per request.
POST /v1/events
curl -X POST https://audit.example.com/v1/events \
-H "authorization: Bearer $LOGARITHM_INGEST_KEY" -H "content-type: application/json" \
-d '{"action":"project.updated","actor":{"id":"u_1","name":"Anna Muster"},
"targets":[{"type":"project","id":"p_1"}],"before":{"name":"A"},"after":{"name":"B"}}'Sign in with token, JWT or your proxyBeta
Admins sign in with a tenant token, an HS256 JWT or the user header of your reverse proxy. Each login sees only its own tenant.
Environment
# token (default)
LOGARITHM_AUTH=token
LOGARITHM_ADMIN_TOKENS="acme=<token>,globex=<token>"
# HS256 JWT
LOGARITHM_AUTH=jwt
LOGARITHM_JWT_SECRET=<32+ characters>
# trusted proxy header
LOGARITHM_AUTH=proxy
LOGARITHM_PROXY_SECRET=<shared secret>More alert rules, and e-mailBeta
The server checks for unusual activity itself, with no cron job. New rules catch mass changes, permission changes outside working hours and permission changes from a new IP. Alerts go to Slack, Teams, a signed webhook or e-mail.
Environment
LOGARITHM_ALERT_RULES=extended
LOGARITHM_ALERT_INTERVAL_MINUTES=5
LOGARITHM_RESEND_API_KEY=<key>
LOGARITHM_ALERT_EMAIL_FROM=audit@example.com
LOGARITHM_ALERT_EMAIL_TO=security@example.comThe demo cannot run the server for you. It needs your own database and a container host.
Read the docsPro
When auditors askLogarithm Pro has the answers.
Slack and Teams alerts with anomaly detection for unusual exports, deletions and failed sign-ins, tamper evidence with an HMAC hash chain, retention periods with archiving, GDPR and Swiss FADP erasure and access requests, CSV export for your customers and forwarding to Splunk, Datadog or signed webhooks.