Most applications already write logs, but ordinary application logs answer a different question. They help engineers debug errors, they are rotated after a few days and anyone with server access can change them. When a customer asks who changed their contract or a regulator asks who viewed a patient record, those logs are rarely enough.

A useful audit log records every security-relevant and business-relevant action as a structured event with the actor, action, target, time, source and outcome, stores it where it cannot be quietly edited or deleted and keeps it for as long as the strictest applicable rule requires.

This article explains what an audit log should contain, which events to record, how to store logs so they hold up in an audit, how long to keep them under common regulations and how to build them into an existing application. It does not cover network or operating system logging, and it is not legal advice.

Key takeaways

  • An audit log answers six questions for every important action: who, what, which record, when, from where and with what result.
  • Audit logs differ from application logs: they are structured, append-only, kept for months or years and readable by people outside engineering.
  • Never record passwords, tokens, full card numbers or more personal data than the event needs.
  • Make logs tamper-evident with append-only storage, hash chaining or write-once storage, and keep them separate from the systems they describe.
  • Retention depends on the rules that apply: PCI DSS requires at least 12 months, SOC 2 audits usually sample a 12-month period, and GDPR requires a defined period no longer than necessary.
  • An audit log only helps if people can search it. A simple audit view in the admin panel ends most investigations in minutes.

Audit log, application log and audit trail

Application logAudit log
Main purposeDebugging and monitoringAccountability, investigations and compliance
Typical contentErrors, warnings, performance dataUser and system actions on data, access and settings
FormatOften free textStructured events with fixed fields
Who reads itEngineersSecurity, compliance, support, auditors and sometimes customers
RetentionDays or weeksMonths or years
Can it change?Rotated and overwrittenAppend-only and protected

The terms audit log and audit trail are usually used interchangeably. Some teams use audit trail for the full history of a single record, such as every change to one invoice, and audit log for the system-wide stream of events.

What each audit log entry should contain

FieldExampleWhy it matters
Event IDevt_7f3a…Lets entries be referenced and checked for gaps
Timestamp2026-11-09T09:14:03.512ZUTC, from a synchronized clock, with milliseconds
ActorUser ID, service account or AI agent IDWho performed the action, including automated actors
Actor contextRole, organization or tenant, impersonation flagShows the permissions in effect and whether support staff acted on someone's behalf
Actioninvoice.updated, user.role_changedA fixed list of action names makes searching reliable
TargetObject type and IDWhich record was affected
ChangesField names with before and after valuesWhat exactly changed, with sensitive values masked
SourceIP address, device, application versionWhere the action came from
OutcomeSuccess, denied or failed, with a reasonFailed and denied attempts often matter most in an investigation
Request or trace IDreq_91c2…Connects the event to application logs and other systems

Use a fixed schema and a controlled list of action names from the start. Free-text messages such as "user updated stuff" make logs impossible to search a year later.

Which events to record

  • Authentication. Sign-ins, failed sign-ins, password resets, multi-factor changes and sign-outs.
  • Authorization. Role and permission changes, access grants and removals, invitations and deactivations.
  • Sensitive data access. Viewing, exporting or downloading records that contain personal, health or financial data.
  • Data changes. Creation, updates and deletion of business records, with before and after values for the fields that matter.
  • Configuration. Changes to settings, integrations, API keys, webhooks and security policies.
  • Administrative actions. Impersonation by support staff, bulk operations and data imports.
  • Automated actions. Changes made by scheduled jobs, integrations and AI agents, recorded under their own identity.
  • Audit log access. Who searched or exported the audit log itself.

Recording every page view usually adds cost without adding value. Focus on actions that change data, change access or expose sensitive information.

What never goes in an audit log

The OWASP Logging Cheat Sheet lists data that should be excluded, removed, masked or hashed before logging. For audit logs, the main items are:

  • Passwords, session identifiers, access tokens and API keys.
  • Encryption keys and database connection strings.
  • Full payment card numbers and bank account details.
  • Health data, government identifiers and other sensitive personal data, unless the event requires them and access to the log is restricted accordingly.
  • Full document contents. Record that a document was viewed or changed, and which fields, not the whole text.

Masking matters for a second reason. Under GDPR, an audit log containing personal data is itself personal data, so the less it contains, the simpler its retention and access rules become.

A JSON audit event with actor, action, target, masked values and trace ID

How to store audit logs so they hold up

An audit log that an administrator can quietly edit proves little. Four design choices make it trustworthy.

  • Append-only writes. The application can add entries but cannot update or delete them. In a database, this means a separate table or schema where the application account has insert rights only.
  • Separation from the main system. Ship events to a separate store, such as a dedicated database, a log platform or object storage, under accounts that the application's administrators do not control.
  • Tamper evidence. Chain entries by including a hash of the previous entry in each new one, so any change breaks the chain, or write batches to storage with write-once protection. Amazon S3 Object Lock, for example, can prevent objects from being deleted or overwritten for a fixed retention period, even by administrators in its compliance mode.
  • Reliable delivery. Write the audit event in the same transaction as the change it describes, or through an outbox table that is shipped afterwards, so a crash cannot leave a change without its record.

Storage cost is rarely the obstacle. A product that records a million events a day at about 1 KB each stores roughly 365 GB a year, which costs a few hundred dollars a year in object storage.

How long to keep audit logs

Rule or frameworkWhat it says about audit logsPractical retention
PCI DSS v4Requirement 10 calls for audit logs of access to cardholder data, kept for at least 12 months with the most recent three months immediately available12 months, three online
HIPAA Security RuleThe audit controls standard requires mechanisms that record and examine activity in systems containing electronic health information. It sets no specific log retention period, while required documentation is kept for six yearsMany organizations keep audit logs for six years
SOC 2Auditors test logging and monitoring controls and sample evidence across the observation period, usually 12 monthsAt least 12 months
GDPRNo fixed period. The storage limitation principle requires keeping personal data no longer than necessary for its purposeA defined, documented period, often 1–2 years for security logs
EU AI ActProviders and deployers of high-risk AI systems must keep automatically generated logs for at least six months, unless other law requires otherwiseAt least six months for those systems

When several rules apply, the longest required period sets the minimum, and GDPR sets the obligation to justify it. Write the retention period for each log type into a policy, automate deletion when it expires and record that deletion happened.

Building audit logs into an existing application

ApproachHow it worksStrengthsLimits
ORM or framework listenersHooks in the data layer capture every change to tracked entitiesCovers all changes made through the application with little codeMisses changes made directly in the database or by other services
Database triggersTriggers write to an audit table on insert, update and deleteCatches every change, whatever the sourceKnows little about the user or the reason unless the application passes it in
Explicit domain eventsThe application emits named events such as contract.approvedClear business meaning, easy to searchRequires discipline to add events everywhere they are needed
Change data captureA tool reads the database's change stream and ships it to a log storeNo changes to application code, low impact on performanceRecords data changes, not who requested them or why

Most teams combine two approaches: data-layer listeners or change data capture for completeness, plus explicit events for important business actions such as approvals, exports and permission changes.

Need to answer who changed what, and prove it to an auditor? We add audit trails, retention rules and audit views to existing applications.

Explore IT outsourcing

Audit logs in delivered projects

Ending detective work on conflicting edits

A B2B supply chain platform, built on Angular and Symfony, lets brokers track relationships between factories and suppliers. Several people edited the same records, changes collided silently and nobody could say who had changed what. A .wrk team added the DamienHarper Auditor bundle to record entity changes in the Symfony data layer, then built a custom audit view where users see the history of each record. Disputes about conflicting edits are now settled by looking at the record's history. Read the platform modernization case study.

Audit-ready results for clinical alerts

A Canadian healthcare startup needed automated alerts when patient-entered data suggested serious complications, across hundreds of thousands of records a month. The queue-based alert engine .wrk built supports 30+ configurable alert types and stores every result in an audit-friendly form, alongside code review gates, role-based approvals and penetration testing that supported SOC 2 Type 2 certification. Read the healthcare platform case study.

History you can query for a data pipeline

For a threat intelligence platform, a .wrk team stored security events as a graph with temporal versioning and a processing ledger, so earlier versions of each vendor, product and vulnerability entry stay available and every processed item is recorded. Read the NEXUS case study.

Audit logs for AI agents

AI agents that act in business systems need the same accountability as people, and a little more. Record each agent under its own identity, and log the request that triggered it, the tools it called with their parameters, approvals given by people and the final result. Keep a trace ID that links all steps of one task. When something goes wrong, this record is the only way to tell whether the agent misread its input, used a tool in the wrong way or acted on an approval it should not have received. Our guide to AI agent security covers the related controls.

Trace of an AI agent task with each tool call, a human approval step and the final result

Make the audit log usable

  • An audit view in the admin panel. Filters by user, record, action and date, with before and after values side by side, answer most questions without engineering help.
  • Per-record history. A history tab on important records, such as contracts, orders or patient files, is often the feature customers value most.
  • Export for auditors. A filtered export with the event fields and a note on how integrity is protected saves days during audits.
  • Alerts on sensitive events. Role changes to administrator, bulk exports and repeated denied access attempts should notify someone.
  • Regular review. A short monthly review of sensitive events catches problems that alerts miss. Our guide to SOC 2 for startups shows how auditors use this evidence.
FAQ

Frequently asked questions

What is an audit log?

An audit log is a chronological, tamper-resistant record of actions in a software system, showing who did what, to which record, when, from where and with what result. It is used for investigations, dispute resolution and compliance.

What is the difference between an audit log and an audit trail?

The terms are usually interchangeable. When teams distinguish them, the audit log is the system-wide stream of events, and the audit trail is the full history of changes to one record or process.

What should an audit log include?

Each entry should include an event ID, a UTC timestamp, the actor and their role, the action, the affected record, the changed fields with before and after values, the source of the request, the outcome and a request or trace ID.

How long should audit logs be kept under GDPR?

GDPR sets no fixed period. Keep audit logs containing personal data only as long as needed for their purpose, define the period in a policy, and delete them automatically when it expires. Many organizations use one to two years for security logs, or longer when another rule, such as PCI DSS or a sector regulation, requires it.

How do you make audit logs tamper-proof?

Write logs to append-only storage that the application's administrators cannot modify, chain entries with hashes so any change is detectable, use write-once storage with a retention lock for archived logs, and restrict and record access to the logs themselves.

To sum up

A useful audit log records important actions as structured events, leaves out secrets and unnecessary personal data, stores entries where they cannot be quietly changed and keeps them for as long as the strictest applicable rule requires. Build it into the data layer, add explicit events for key business actions and give people a simple way to search it.

.wrk builds and modernizes business applications for companies in the US and Europe, including audit trails, permission models and compliance features for healthcare, legal and enterprise platforms.

Preparing for an audit or a customer security review? Tell us about your application, and we will propose an audit logging design with retention rules and an audit view.

Explore IT outsourcing