evloghq/evlog/build-audit-logs

Claude Code and agent skill by evloghq/evlog

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

Build or review audit trails in TypeScript/JavaScript apps using evlog (pipelines, typed actions, denials, retention, compliance-style reviews). For application code, not for extending the evlog package.

Install

npx vskill@latest install evloghq/evlog/build-audit-logs

SKILL.md

The same SKILL.md was published earlier as evloghq/evlog/build-audit-logs.

Build or Review an Audit System with evlog

For application developers who either need to add an audit trail to their product, or who already have one and want it reviewed. Walks through the design calls, the end-to-end implementation, and a review checklist for an existing setup.

This skill assumes the audit lives in your app. To extend the evlog package itself (new audit helper, new drain wrapper), see the contributor skills under .agents/skills/.

Quick reference: call-site cheat sheet

When you already know the system is wired and just need to remember the API:

SituationHelper
Inside a request handler, action succeededlog.audit({ action, actor, target, outcome: 'success' })
Inside a request handler, AuthZ deniallog.audit.deny('reason', { action, actor, target })
Standalone job / script / CLI (no request)audit({ action, actor, target, outcome })
Auto-record success / failure / denied for a functionwithAudit({ action, target }, fn)
Recording a state changeadd changes: auditDiff(before, after)
Centralised typed action vocabularydefineAuditCatalog('billing', { INVOICE_REFUND: { target: 'invoice' } }), or defineAuditAction('invoice.refund', { target: 'invoice' }) for one-offs
Asserting audits in testsmockAudit(), then assertAudit() or toIncludeAuditOf()

AuditFields schema (always provide action, actor, outcome; target strongly recommended; the rest is filled in for you):

ts
interface AuditFields {
action: string // 'invoice.refund'
actor: { type: 'user' | 'system' | 'api' | 'agent', id: string, email?, displayName?, model?, tools?, reason?, promptId? }
outcome: 'success' | 'failure' | 'denied'
target?: { type: string, id: string, [k: string]: unknown }
reason?: string
changes?: { before?: unknown, after?: unknown, patch?: AuditPatchOp[] }
causationId?: string
correlationId?: string
version?: number // defaults to AUDIT_SCHEMA_VERSION
idempotencyKey?: string // auto-derived from action+actor+target+timestamp
context?: { requestId?, traceId?, ip?, userAgent?, tenantId?, ... } // filled by auditEnricher
signature?: string // added by signed(drain, { strategy: 'hmac' })
prevHash?: string // added by signed(drain, { strategy: 'hash-chain' })
hash?: string // added by signed(drain, { strategy: 'hash-chain' })
}

What "audit logging" actually means

An audit log answers a forensic question: who did what, on which resource, when, from where, with which outcome. That's a different shape from observability logs, which is why the operational rules differ:

Audit logObservability log
Question"Who tried to do what, was it allowed?""How did this request behave?"
SamplingNever (force-keep)Often (head + tail)
Retention1 – 7 years (compliance)30 – 90 days
MutabilityAppend-only, tamper-evidentMutable, lossy
AudienceAuditors, security, legalEngineers
StorageOften dedicated (separate dataset / DB)Shared with telemetry

evlog ships the audit layer as a thin extension of its wide-event pipeline (a typed audit field on BaseWideEvent plus a few helpers and drain wrappers). The point is that you compose with the primitives the app already uses: same drains, same enrichers, same redact, same framework integration. There is no parallel system to maintain.

Mental model

text
log.audit(...) ──► sets event.audit ──► force-keep ──► auditEnricher ──► redact ──► every drain
└─► auditOnly(signed(fsDrain))
Building blockRoleRequired?
log.audit() / audit() / withAudit()Sets event.audit and force-keeps the eventYes
auditEnricher()Auto-fills event.audit.context (req / trace / ip / ua / tenantId)Recommended
auditOnly(drain)Filters the drain to events with event.audit setRecommended
signed(drain, ...)Adds tamper-evident integrity (HMAC or hash-chain)Optional (compliance)
auditRedactPresetStrict PII preset for audit eventsRecommended
mockAudit()Captures audit events in testsYes (in tests)

Design calls before writing code

Make these explicit and write them down somewhere a security reviewer can find. Without a written rule, the system can't be audited. Auditors look for the policy first, then the enforcement.

1. Where do audits live?
DrainUse whenTrade-offs
FS (evlog/fs + signed)Self-hosted, simple, you control the diskManual rotation/backup; single-process unless you persist hash-chain state externally
Dedicated Axiom datasetYou already use AxiomEasy queries, separate retention/billing; cost scales with volume
Postgres / Neon / AuroraYou want SQL queries, joins with app dataNeed a schema, indexes, retention job; idempotency key prevents duplicates
S3 + Object LockAppend-only WORM compliance (HIPAA / FINRA)Read latency; pair with a queryable mirror (Athena)
Multiple drainsDifferent audiences (engineers ↔ legal)Use auditOnly per drain; drains fail in isolation by design
Rule of thumb. Pick at least two: a queryable one (Axiom / Postgres) for day-to-day forensics + an append-only one (FS journal with hash-chain, or S3 Object Lock) as the compliance artefact. The two-drain pattern protects against vendor outages and admin mistakes on the queryable side.
2. Do you need integrity (signed)?

Yes if any of:

  • A compliance framework requires tamper-evidence (SOC2 CC7, HIPAA §164.312(c)(1), PCI 10.5).
  • The drain is mutable by engineers / admins.
  • You may need to prove to a regulator that no events were modified after the fact.

Skip if:

  • Drain is already WORM (S3 Object Lock, BigQuery append-only, Postgres with row-level immutability + monitored DDL).
  • You're prototyping.

Strategies:

  • 'hmac': per-event signature; quick to verify; rotate secret annually and embed a key id (extend AuditFields).
  • 'hash-chain': sequence integrity; deleting a row breaks the chain forward; persist state.{load,save} if you run multiple processes (Redis is the typical store).
3. Multi-tenancy?

If the app is multi-tenant, tenant isolation on every audit event is non-negotiable. A query that mixes tenants is a privacy incident. Wire it once in the enricher:

ts
auditEnricher({ tenantId: ctx => resolveTenant(ctx) })

If the app uses Better Auth, auditEnricher can also bridge the authenticated session into audit.context. See the Better Auth integration (evlog/better-auth, https://www.evlog.dev/use-cases/better-auth/overview) for wiring identifyUser alongside the audit pipeline.

Then either (a) partition the audit dataset by audit.context.tenantId, or (b) one drain per tenant if hard isolation is required. Never query audits without a tenant filter.

4. Retention

Pick a window per drain and document it. Enforce at the drain layer, not in app code, because the drain already has audited mechanisms for it (lifecycle policies, DELETE jobs, dataset retention).

FrameworkTypical retention
SOC21 year minimum, 7 years recommended
HIPAA6 years
PCI DSS1 year (3 months immediately accessible)
GDPR"As long as necessary" (see "GDPR vs append-only" below)

How to enforce per drain:

  • FS: createFsDrain({ maxFiles }) + a daily compactor.
  • Postgres: DELETE FROM audit_events WHERE timestamp < now() - interval '7 years' on a cron.
  • Axiom / Datadog / Loki: dataset-level retention policy.
5. GDPR vs append-only

The right to be forgotten collides with audit immutability. Recommended pattern:

  1. Keep audit rows immutable and chain-verified.
  2. Encrypt PII fields (email, name, IP) with a per-actor key held outside the audit store.
  3. To "forget" a user, delete their key. The audit row stays, the chain stays valid, the PII becomes unreadable (crypto-shredding).

A built-in cryptoShredding helper is on the roadmap; until then, encrypt in a custom enricher.

Step-by-step buildout

Step 1: Wire the pipeline (one-time)

The wiring shape is the same in every framework: register auditEnricher() so event.audit.context gets requestId, traceId, ip, userAgent, and (if configured) tenantId automatically, then add a main drain plus an audit-only drain.

The minimal Nuxt / Nitro setup looks like this:

ts
// server/plugins/evlog.ts
import { auditEnricher, auditOnly, signed } from 'evlog'
import { createAxiomDrain } from 'evlog/axiom'
import { createFsDrain } from 'evlog/fs'
export default defineNitroPlugin((nitroApp) => {
const auditSink = auditOnly(
signed(createFsDrain({ dir: '.audit/' }), { strategy: 'hash-chain' }),
{ await: true },
)
const main = createAxiomDrain({ dataset: 'logs' })
nitroApp.hooks.hook('evlog:enrich', auditEnricher({
tenantId: ctx => ctx.headers?.['x-tenant-id'],
}))
nitroApp.hooks.hook('evlog:drain', async (ctx) => {
await Promise.all([main(ctx), auditSink(ctx)])
})
})

For Hono, Express, Next.js, or standalone scripts / workers, see `references/framework-wiring.md`. The pattern is identical. Only the framework integration helper changes.

Step 2: Define the action vocabulary

Audits get queried and alerted on by audit.action. A typo is a missing alert, so centralise the list. For a bounded context with several actions, prefer a catalog: one prefix, typed keys, autocomplete on the wire format ${prefix}.${KEY}:

ts
// app/audit/billing.ts
import { defineAuditCatalog } from 'evlog'
export const billingAudit = defineAuditCatalog('billing', {
INVOICE_REFUND: { target: 'invoice' },
PLAN_CHANGE: { target: 'subscription' },
})

At the call site: log.audit(billingAudit.INVOICE_REFUND({ actor, target, outcome: 'success' })).

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/evloghq/evlog/build-audit-logs/badge)](https://verified-skill.com/skills/evloghq/evlog/build-audit-logs)

Something wrong with this skill or its page? Tell us.