Skip to main content
Engineering7 min readOctober 28, 2025

Audit Logging for SaaS: Compliance and Debugging

Audit logs serve two masters — compliance auditors and engineers debugging production issues. Here's how to build an audit logging system that satisfies both.

James Ross Jr.
James Ross Jr.

Strategic Systems Architect & Enterprise Software Developer

Audit Logs Are Not Application Logs

There's a common mistake in SaaS applications where "audit logging" means writing a few extra lines to the application log when something important happens. Application logs and audit logs serve fundamentally different purposes, have different requirements, and should be different systems.

Application logs help engineers understand system behavior — debugging errors, tracing request flows, measuring performance. They're verbose, transient, and often unstructured. You search them when something goes wrong and purge them when they get too large.

Audit logs create a tamper-evident record of who did what, when, and to which data. They're structured, immutable, and retained for defined periods (often years). They serve compliance requirements, security investigations, and customer trust. An auditor reviewing your SOC 2 controls will examine your audit logs. A customer asking "who changed this record last Tuesday" will be answered by your audit logs.

Building these as separate systems from the start avoids the painful extraction later when a compliance requirement forces you to separate them.


What to Log

The most common failure in audit logging is logging too little. The second most common is logging too much without structure. Both make the audit log useless for its intended purposes.

Every data mutation should be logged. Creates, updates, and deletes on business-critical entities. The log entry should capture the actor (who performed the action), the action (what they did), the target (which entity was affected), the timestamp (when it happened), and the change details (what the data looked like before and after).

Authentication events include successful logins, failed login attempts, password changes, MFA configuration changes, session creation and termination, and API key usage. These events are critical for security investigations and are specifically examined in SOC 2 audits.

Authorization events capture access grants and revocations. When a user is given admin access, when a team member is removed from a project, when an API key's permissions are changed — all of these should appear in the audit log. They complement your role-based access control by providing a history of how permissions have changed over time.

Administrative actions include configuration changes, feature flag modifications, tenant settings updates, and billing changes. Any action performed by a system administrator that affects the behavior of the application or the experience of users.

What not to log. Read operations on non-sensitive data don't typically need audit logging (though access to sensitive data like PII or financial records should be logged). System-to-system operations that don't involve user-initiated actions can go in application logs rather than audit logs. Performance metrics and health checks are application log material.


The Implementation Architecture

An audit logging system has specific technical requirements that distinguish it from general-purpose logging.

Immutability. Audit log entries must not be modifiable or deletable through the application. This is both a compliance requirement and a trust requirement. If a malicious actor gains access to your system, the audit log should be the thing that reveals their actions. If they can also modify the audit log, it's worthless.

Implement this by writing audit logs to an append-only data store. If using a database, the audit log table should have no UPDATE or DELETE permissions for the application's database user. If using a log aggregation service, ensure the retention policy is enforced by the service, not the application.

Structured data. Every audit log entry should follow a consistent schema. A structured format makes audit logs queryable and analyzable — you can answer questions like "show me all changes to customer records in the last 30 days" or "who accessed this user's data."

A reasonable schema includes: id, timestamp, actor_id, actor_type (user, system, API key), action (created, updated, deleted, accessed), resource_type, resource_id, tenant_id, changes (JSON diff for updates), ip_address, user_agent, and metadata (additional context).

Asynchronous writing. Audit log writes should not block the user's request. Emit the audit event synchronously (to guarantee it's captured), but write to the audit log store asynchronously via a queue. This prevents audit logging latency from affecting application performance and provides retry capability if the log store is temporarily unavailable.

Tenant isolation. In a multi-tenant SaaS, audit logs must be strictly tenant-isolated. Tenant administrators should be able to view audit logs for their organization but never for other tenants. If you're providing audit log access to customers as a feature, the access control must be airtight.


Retention, Access, and Operationalization

Retention policies should be defined before the system is built. Compliance requirements typically specify minimum retention periods — SOC 2 commonly requires one year, HIPAA requires six years, financial regulations may require seven. Define your retention period based on your compliance requirements and your customer contracts, and automate purging of logs that exceed the retention period.

Access controls on audit logs should be the strictest in your system. Only a small number of designated roles should be able to read audit logs. No one should be able to modify or delete them through the application.

Search and export capabilities turn audit logs from a compliance checkbox into a useful product feature. Enterprise customers value the ability to search their organization's audit log and export it for integration with their own compliance tools. Building a search interface with filters for date range, actor, action type, and resource is a relatively small investment that significantly increases the perceived value of your platform.

Alerting on suspicious patterns extends audit logging from passive record-keeping to active security monitoring. Login attempts from unusual IP addresses, bulk data exports, permission escalation events — these patterns in the audit log can trigger automated alerts that enable rapid response to security incidents.

Audit logging is one of those infrastructure investments that feels like overhead until the moment you need it. When that moment arrives — a security incident, a compliance audit, a customer asking who changed their data — having comprehensive, structured, immutable audit logs is the difference between a confident response and a panicked scramble.


Keep Reading