How to keep useful security and audit logs without breaking GDPR: what to log, what to avoid, how long to keep it and how to enforce deletion.
In this article
Logs are essential for security and troubleshooting, and they usually contain personal data. GDPR does not forbid logging. It asks that you log for a clear purpose, collect only what you need, protect the logs, and delete them when that purpose no longer justifies keeping them. The practical answer is a short written policy that says what you log, why, who can see it and how long it stays.
Why logs fall under GDPR
A log line that records a user ID, email address, IP address, device identifier or a customer's search query relates to an identifiable person. That makes the log personal data, and the normal principles apply: lawfulness, purpose limitation, data minimisation, storage limitation, integrity and confidentiality, and accountability.
Two points catch teams out. First, logs are often spread across many systems: web servers, application frameworks, databases, load balancers, cloud audit trails, email gateways and third-party monitoring tools. Each one can hold personal data. Second, nobody reviews logs closely until an incident, so sensitive values can sit there unnoticed for years.
Seen positively, good logging is itself part of the security that GDPR expects. You cannot detect misuse of personal data without records of who accessed what. The aim is balance, not abstinence.
Decide the purpose before you decide the fields
Start with purposes, then derive what to record. Typical purposes include:
- Security monitoring: detecting failed logins, privilege changes and unusual access.
- Audit trail: showing who changed or viewed important records.
- Operations: diagnosing errors and performance problems.
- Billing or contractual evidence: where you must prove what was delivered.
Each purpose has different needs. Debug logs might be kept for days. Security events may justify a longer period. An audit trail for finance records may follow a different rule again. Treating all logs as one bucket with one retention period usually means either deleting useful evidence too early or hoarding personal data for no reason.
Document the lawful basis for each category. For security logging many organisations rely on legitimate interests, but you should record your balancing reasoning rather than assume it. Whether that fits your case depends on your situation, so confirm it with your data protection adviser.
What to log and what to keep out
Log events, not content. A security event such as a failed login needs a timestamp, a user identifier, the source and the outcome. It does not need the password that was typed.
| Generally useful | Generally avoid or mask |
|---|---|
| Timestamp with time zone | Passwords, tokens, API keys, session cookies |
| Event type and outcome | Full payment card numbers or bank details |
| Internal user or account ID | Health data, special category data in free text |
| Source IP or device ID where needed | Full request bodies containing form data |
| Resource affected (record ID, not the record) | Email addresses or names in URLs and error messages |
A frequent mistake is logging an entire request on error. It makes debugging easy and fills your logs with whatever customers typed. Build redaction into your logging library so that known sensitive fields are masked before the line is written. Our guide to building a secure login system covers which authentication events are worth recording.
Where you can, use stable internal IDs instead of names or emails. That reduces exposure and keeps logs useful. Remember that a lookup table connecting the ID to a person is still available to whoever holds it, so this is pseudonymisation rather than anonymisation.
Setting retention periods
GDPR requires you to keep personal data no longer than necessary for the purpose. It gives no universal number for logs. You set the period, justify it and stick to it.
A sensible method:
- List each log type and its purpose.
- Ask how far back someone realistically needs to look for that purpose. For example, how long does it take your team to notice and investigate a suspicious event?
- Check for sector or contractual requirements that set a minimum, and note them.
- Choose a period, and record the reason in one sentence.
- Choose what happens at the end: deletion, aggregation into non-personal statistics, or archive with tighter access.
If someone asks why you keep application logs for a given time, the answer should come from this record, not from a default setting that nobody chose. Many logging tools keep data indefinitely unless you configure otherwise, so check the defaults in each product you use. Backups of log stores count too. Our article on why untested backups fail is a useful reminder that backups need their own retention rules.
Protecting logs and limiting access
Logs are a target. An attacker who reads them may find tokens, addresses and behaviour patterns. Apply the same security principles you use elsewhere:
- Restrict access to those who need it, and review the list regularly.
- Send logs to a central, separate store so an intruder on one server cannot easily erase their tracks.
- Encrypt data in transit and at rest.
- Make audit logs tamper-evident, for example with append-only storage or write-once controls.
- Log access to the logs themselves where they hold sensitive data.
- Check what third-party monitoring or logging services receive, and whether they act as a processor under a proper contract.
Support staff often ask for broad log access to diagnose issues. Provide scoped views or masked queries instead, and treat full access as an exception with a reason recorded.
Making deletion actually happen
A retention policy that exists only as a document is a risk. Enforce it with tooling.
- Use lifecycle rules in cloud storage and log platforms that delete or archive data automatically after the chosen period.
- Apply time-to-live settings in databases and search indexes that hold event data.
- Test deletion. Confirm that data older than the limit really is gone, including from replicas and exports.
- Track exceptions, such as logs held for an investigation, with an owner and an end date.
- Include logs in your process for handling data subject requests, so you can find personal data in them when you need to. See DSAR handling in business software for how to design this.
Treat a legal or investigative hold as a documented exception to retention rather than a reason to stop deleting everything.
Who should decide
Logging policy touches engineering, security and data protection, so no single team should decide alone. Engineers know what is technically useful, security knows what must be monitored, and your data protection contact checks purpose and period. A short review meeting once a year, with the policy and a sample of real log lines on the table, is usually enough to keep the three views aligned.
Common mistakes
- Keeping everything forever because storage is cheap.
- Logging secrets, tokens or full payloads in error handlers.
- Using different retention in each tool without a central view.
- Giving all engineers read access to production logs.
- Forgetting that a security incident response plan needs logs to work. See our incident response plan outline for what responders typically need.
What to do next
- Inventory where logs live, including cloud audit trails and third-party tools.
- Write a one-page logging and retention policy with purpose, fields, access, period and deletion method for each log type.
- Add redaction to your logging code and check recent logs for leaked secrets or personal data.
- Switch on automatic deletion and test it.
- Review the policy at least once a year, and check the current guidance from the Data Protection Commission, which is the place to confirm how the rules apply to your case.
This is not legal advice.
If you would like help with this, the CloudWiss team in Dublin can talk it through, from deciding what to monitor to configuring retention and access controls. Read more about our cyber security services.
Share this article
General educational information, not legal or professional advice for your specific situation.
