Cloud
Audit Logging
Immutable, event-driven audit trail for compliance and security.
Overview
The audit system emits structured, immutable events onto the AxilJS global event bus. It captures who did what, when, where, and whether it succeeded — providing the foundation for SOC2, HIPAA, and GDPR compliance.
Automatic Request Auditing
Attach the middleware globally to log every HTTP request automatically.
typescript
Each request generates an event containing:
- Action — HTTP method and path (e.g.
POST /api/users) - Actor — Authenticated user ID or
anonymous - Tenant — Resolved tenant ID from multi-tenancy middleware
- Request ID — Correlation ID from the request lifecycle
- Status — HTTP status code and success/failure flag
- Duration — Response time in milliseconds
- Client — IP address and user agent
Manual Audit Events
Log business-level actions that don't correspond to HTTP requests.
typescript
Persisting Audit Events
Subscribe to the global event bus to store events in your preferred backend.
typescript
Architecture
The audit middleware uses Node.js finish and close response lifecycle events
rather than monkey-patching res.raw.end. This ensures:
- Safe operation with streaming responses
- No interference with other middleware
- Exactly-once event emission per request
- Compatibility with all AxilJS response methods
Options
typescript
Event Schema
typescript