Yashveer Singh
Connect
<- All posts
Security, Auth, and Compliance6 min read

Logging Customer Data: The Privacy Mistakes That Get You Sued

Customer data in application logs is a privacy liability that most engineering teams create accidentally rather than deliberately. Personally identifiable information logged for debugging purposes stays in log storage systems indefinitely, is accessible to everyone with log access, and creates data retention violations under GDPR, CCPA, and similar regulations. The fix is a logging hygiene policy enforced at the instrumentation level, not at the storage level.

Written by Yashveer Singh, founder of Yashveer Labs.

What you need to know

  • PII in application logs is a regulatory liability. GDPR, CCPA, and similar laws apply to data in logs just as they apply to data in databases. Log storage is not exempt.
  • The most common source of PII in logs is debug instrumentation: engineers adding detailed context to troubleshoot a bug and not removing it when the bug is fixed.
  • Log opaque IDs (user IDs, order IDs) not identifying information (email, name, address). The ID allows you to trace the specific user or record in your database when debugging.
  • Log retention policies apply to logs. Logs stored indefinitely with PII are a data minimization violation. Define retention periods and enforce them.
  • Auditing existing logs for PII is the immediate action. Finding and removing instrumentation that writes PII is the fix.

The core argument

The typical path to PII in logs is straightforward: an engineer is debugging a production issue involving user authentication. To understand the flow, they add a log line that includes the user's email address, the request headers, and the authentication token. The bug is fixed. The log line stays. Three months later, the logs are rotating through a retention window that is far longer than it should be, the email addresses of thousands of users are sitting in a logging platform accessible to everyone with a developer account, and nobody remembers that the instrumentation was added in the first place.

This is not a hypothetical. It is the pattern that produces regulatory findings in most breach investigations involving log data. The fix requires both a culture change and a technical control. The culture change is establishing that identifying information does not belong in logs as a default, and that log entries should reference internal IDs that allow lookup rather than embedding the identifying data directly. The technical control is automated PII detection in the CI pipeline or at log write time that catches patterns that look like email addresses, phone numbers, or payment data before they reach log storage.

The data subject access request (DSAR) problem is the other dimension. Under GDPR, a user who requests a copy of their personal data is entitled to receive everything your systems hold about them. If your logs contain their email address, those log entries are in scope for the DSAR. Log storage systems are not designed for targeted data retrieval. Complying with a DSAR that includes log data requires either maintaining indexed metadata about which log entries relate to which user, or accepting that log compliance is a gap. Building the logging discipline to avoid PII in logs from the start is simpler than retrofitting a DSAR compliance layer on top of logs that already contain it.

Common mistakes

  1. Logging full request bodies without scrubbing sensitive fields. An API endpoint that logs the full request body will log password fields, payment data, and personal information from form submissions. Explicitly filter request body logging to known safe fields rather than logging everything.
  1. Logging authentication tokens and API keys. A log line that includes an authentication header or an API key is equivalent to storing that credential in plaintext in your log system. Authentication tokens and API keys should be replaced with truncated versions or omitted entirely in logs.
  1. Not setting a log retention period. Logs retained indefinitely accumulate PII from every debug instrumentation that ever ran. Define a retention period (typically 30 to 90 days for application logs), enforce it in your logging platform configuration, and document it in your privacy policy.
  1. Treating log access as unrestricted. Logs are data. Access to log systems should follow the principle of least privilege: developers can access logs for the services they own, not logs for all services. Production database query logs and authentication service logs should have more restricted access than application debug logs.
  1. Not including log PII review in the code review process. PII in logs is introduced at the instrumentation level. Code review is the right place to catch it. Add log statement review to your code review checklist: does this log any identifying information that should be replaced with an ID?

Where to start

  1. Run a PII scan on your last 30 days of logs. Search for email patterns, phone number patterns, and any field names that typically contain personal data (name, email, phone, address). List the log entries that contain PII and trace them to the instrumentation code.
  1. Replace identifying fields with IDs in the top five PII-containing log patterns. Each instance where an email address appears in a log, replace it with the user_id. Each instance where a customer name appears, replace it with account_id. The identifying data remains accessible in the database when needed for debugging.
  1. Set a log retention policy and enforce it in your logging platform. Most logging platforms (Datadog, Loki, CloudWatch) support automatic retention periods. Set 30 to 90 days for application logs and verify that older logs are being deleted on schedule.

Related reading

FAQ

Frequently asked

Author

The engineering bet behind Yashveer Labs

The bet I am running with Yashveer Labs is simple. Most software is built by people who treat it as a job. I treat it as a craft. Yashveer Singh, founder. Five production systems on the board so far. The arc points at machine learning, AI engineering, and cybersecurity. If your project is in any of those orbits, you are reading the right page.

Related reading