How to Design Audit Logs and Traceability

Designing audit logs that answer who changed what and when in business applications; what to record, what never to record, and how to protect the records.

The short answer

An audit log is a tamper-resistant record of who did what to a business record, when, from where and with what result; it is different from the application log kept for debugging.

A good design separates three layers; the activity history shown to users, the audit trail kept for security and compliance, and the technical application log.

Passwords, session values, access tokens and sensitive personal data should not be written to logs; records should be append-only, access to them restricted, and retention periods decided up front.

An audit log is a tamper-resistant record of who did what to a business record, when, from where and with what result. When a customer asks “why did this shipment’s address change?”, or when a security incident is investigated, the answer comes from here.

This article explains why the audit log should be designed separately from the application log in business software, which fields an entry needs, what should never be written, and how to protect the records. The examples come from design decisions in the logistics management platform and the Ders Alanı platform I built.

Why a separate record?

The “Security Logging and Alerting Failures” entry (A09) in OWASP’s 2025 list names the typical gaps: auditable events such as logins, failed logins and high-value transactions not being logged, or logged inconsistently; and log integrity not being protected from tampering. The same entry recommends an audit trail for all transactions with integrity controls to prevent tampering or deletion, giving append-only database tables as an example.

The application log does not meet that need. It is written for developers to debug, its format changes often, it is kept briefly, and it is usually not tied to a business record. An audit log is tied to the business record, has a fixed format and serves as evidence.

Three layers, three readers

Layer Its reader The question it answers Example
Activity history Operations staff and customers What happened to this record? “Shipment delivered at 14:20; signature and location captured”
Audit trail Administrators, security, compliance Who changed what, when and from where? User ID, action, old and new values, IP address, outcome
Application log Developers and operators Why did the system behave this way? Stack trace, duration, dependency response

In the logistics platform, every shipment has an activity history; status changes are written there and users see it on screen. On the security side, audit records, log retention and destruction policies are defined separately. The split keeps the history shown to customers simple, while the detail a security review needs stays away from unauthorised eyes.

What an audit entry should contain

OWASP’s logging guidance asks for “when, where, who and what” to be recorded for each event. In a business application that means:

  • When: the event time, in international format and with a time zone.
  • Where: which application, which endpoint or screen, which operation.
  • Who: the user’s identifier (not their name, but their stable ID), role and organisation; if a system or assistant acted, its identity and on whose behalf it acted.
  • What: the type of action, the type and ID of the record affected, and the old and new values or the list of fields that changed.
  • Outcome: did it succeed, was it refused, and why?

The last item is often skipped. A refused access attempt is as valuable as a successful action; someone trying to open another customer’s record shows up only in the refusals. Authorisation decisions should therefore be written to the audit trail too. The authorisation design itself is covered in authorisation in multi-role systems.

What should never be written

OWASP’s guidance says the following should usually not be recorded directly in logs, but removed, masked, sanitised, hashed or encrypted instead:

  • passwords,
  • session identifier values (a hashed value if session tracking is needed),
  • access tokens,
  • sensitive personal data,
  • application source code,
  • user information in URLs and sensitive query-string values.

It also reminds readers never to log data without a legal basis. In Türkiye, Article 4 of the Personal Data Protection Law No. 6698 requires personal data to be relevant, limited and proportionate to its purpose and kept only as long as necessary; Article 12 requires technical and administrative measures against unlawful access. The EU’s GDPR sets similar principles. An audit log contains personal data too: at least the identity of whoever acted. “Log everything in case we need it” conflicts with these principles.

Protecting the records

An audit log that can be changed is not evidence. OWASP’s guidance recommends building in tamper detection so you know if an entry was modified or deleted, copying logs to read-only media as soon as possible, recording all access to logs, and restricting and periodically reviewing who may read them. NIST SP 800-92 treats log management as a process covering collection, storage, protection and disposal.

At the application level, that translates to:

  1. Append only. The application’s database user has no update or delete rights on the audit table; it can only insert new rows.
  2. Separate permission. The roles that can read audit entries are separate from the roles that edit business records.
  3. A retention and disposal policy. How long each kind of entry is kept is written down; expired entries are destroyed by a defined process, not by hand.
  4. Noticing when logging stops. Someone must notice when the flow of entries stops; a silently stopped audit log is more dangerous than none, because it creates false confidence.

Undo and correction

Mistakes in the field are unavoidable: the wrong shipment is marked “delivered”, the wrong driver is assigned. There are two ways to fix it: restore the record and delete the mistaken action, or add a new action that corrects it. In an auditable system, only the second is right.

In the logistics platform, a mistaken action can be undone without corrupting the record, and every change is written to the shipment’s activity history. The undo is an action too; the history shows both the mistake and who undid it, and when. That shows what really happened, both in a dispute with a customer and in an internal review.

Concurrent writes and repeated requests

Traceability does not end with writing logs; the record itself has to be consistent. Two problems are common. The first is two users changing the same record at once and one change being silently lost. In Ders Alanı this is solved with revision-based optimistic concurrency: if another writer has changed the revision, the stale writer is refused. The second is the same request arriving twice over a weak connection. In Ders Alanı, operations are idempotent: sending the same operation again does not change the result, and a repeat that conflicts with different content returns its own error. In both cases the audit trail shows what really happened, instead of actions that look duplicated or vanish.

Mistakes that weaken an audit trail

  • Recording only successful actions. Refused access is the first trace of an attack.
  • Writing the user’s name as the identifier. Names change; write the stable user ID.
  • Making the audit trail a column on the business table. A “last updated by” column shows the last change, not the history.
  • Logging sensitive data “for now”. A password or token written once lives on in backups and archives for years.
  • Leaving system actions anonymous. Scheduled jobs, integrations and AI assistants should be recorded with their identity as well. Auditing assistants is covered in AI agents in business software.

History is a record, not a story edited later

Traceability means meeting three different needs with three separate layers: an activity history for users, an audit trail for security and compliance, and an application log for developers. The audit trail should hold when, where, who, what and the outcome, leave sensitive data out, be append-only and be governed by a defined retention policy. An undo is a recorded action too, so the history becomes a record of what actually happened, not a story corrected afterwards.

Frequently asked questions

What is the difference between an audit log and an application log?
An application log helps developers follow errors and performance; it is kept briefly and holds technical detail. An audit log records actions on business records as evidence; it answers who changed what and when, and is kept for a longer, defined period.
Can audit log entries be deleted?
Not from inside the application, and not by ordinary users. OWASP recommends integrity controls such as append-only tables. Entries past their retention period are destroyed under a defined policy.
How should an undo appear in the audit log?
An undo should not erase the original entry; it should be a new action that is recorded in its own right. Both the mistaken action and its correction then remain visible in the history.
Does an audit log contain personal data?
Usually yes; at the very least the identity of the person who acted. Access should therefore be restricted, unnecessary personal data left out, and retention set in line with data-protection law.

Sources

  1. OWASP Top 10:2025, A09 Security Logging and Alerting Failures owasp.org
  2. OWASP Logging Cheat Sheet cheatsheetseries.owasp.org
  3. NIST SP 800-92, Guide to Computer Security Log Management csrc.nist.gov
  4. Turkish Personal Data Protection Law No. 6698 (mevzuat.gov.tr, Turkish) mevzuat.gov.tr

Projects this article draws on