The PHI you are leaking into your own logs
Nobody decides to write patient data into a log file. It arrives there as a by-product of debugging, error reporting and support, and it stays there for as long as the retention policy nobody set.
A claim fails to build. Somebody adds a log line so that next time there is something to look at. The line prints the claim object.
The claim object contains the patient's name, date of birth, member identifier, address, diagnosis codes and the name of the provider who saw them. The log line goes to a file, the file goes to a log aggregator, the aggregator is a third-party service, and the service retains it for ninety days by default and indexes every field for search.
That is a disclosure of protected health information to a vendor, it happened without anyone deciding it, and it is the single most common way a technically careful billing system ends up handling PHI in places it never meant to.
Where it actually accumulates
The log line is the obvious one. The list is longer, and the rest of it is harder to see:
- Exception reports. Error tracking services capture local variables by default. An exception thrown anywhere near a patient record ships that record off-site, complete, with a nicely formatted stack trace.
- Request logs. A path or a query string containing a member identifier, a date of birth, or an account number is logged by the web server, the load balancer, the proxy and the browser's history.
- Outbound HTTP logs. An integration that logs request and response bodies for debugging logs the eligibility response too.
- Database slow query logs. A parameterised query logs its parameters.
- Email. An exception notification with the record attached, a "failed claims" summary to an internal address, an alert that quotes the row that caused it.
- Support tickets and screenshots. The most common route of all, and the one no amount of code review catches. A user attaches a screenshot of the screen that is broken, and the screen is full of a real patient.
- Backups and database dumps on a laptop. A copy of production taken to reproduce a bug is a copy of production.
- Analytics. A page title or a URL sent to an analytics service. Anything that puts an identifier in a page title puts it in the analytics record.
Read that list as a design input rather than a scolding. Each item is a place where the default behaviour of a reasonable tool conflicts with the minimum necessary principle, and each one is fixable once, structurally.
The structural fix: logs carry references, not records
The approach that holds up is not "remember to redact". Nobody remembers. It is to make the identifier the only thing that is ever logged, and to make logging a record impossible by construction.
Three things do most of the work:
A log that takes fields, not objects. Structured logging with an explicit allow-list: the claim identifier, the payer identifier, the state, the error code. Passing an entity to the logger is a type error or a lint failure, not a judgement call. If the model has a __toString or a default serialisation that prints its contents, override it to print its class and its identifier.
Identifiers that are yours, not the patient's. Internal surrogate keys, used everywhere in logs, alerts, queue names, filenames and URLs. A log line that says claim 01JB7C is debuggable by anyone with access to the database and useless to anyone without it. A log line that says member W1234567801 is neither.
Redaction at the boundary, as a last line. A filter in front of the exception reporter and the log shipper that strips the fields you know are sensitive, by name, from payloads and from stack frames. It will not catch everything, which is why it is the last line rather than the strategy, but it catches the accident in the code somebody wrote at six in the evening.
Two more that are cheap and often skipped: never put an identifier in a URL path or query string where a POST body will do, and turn off local variable capture in the exception reporter rather than trusting yourself to keep patient data out of local variables.
Retention is a decision somebody has to make
A log you keep for a year is a record you hold for a year. The questions are: what is in it, how long do we keep it, who can read it, and is it encrypted where it sits.
If the answer to the first question is "references only", the other three get much easier, and that is the main practical argument for the discipline above. If the answer is "we are not sure", then the honest position is that the log store is a system that handles PHI and has to be treated as one — access controlled, audited, covered by the agreement with whoever runs it, and included in the risk analysis.
That third point is the one that catches people. A log aggregator holding PHI is a vendor processing PHI on your behalf, which puts it inside the business associate relationship rather than outside it. Choosing a vendor for the engineering team is then a decision with a contractual dimension, and it is far better to find that out before the data is already there.
What bites once it is live
The leak arrives with a library upgrade. A dependency starts logging request bodies at info level in a minor release. Nothing in your code changed. Check what your dependencies log, and pin the behaviour where you can.
Developers need to debug production. A policy of "no PHI in logs" with no alternative route means somebody will copy a record into a scratch file to work on it. Give them a supported path — a masked view, a reproduction harness that takes an identifier and builds a synthetic equivalent — or the policy will be routed around by people trying to do their jobs.
Support is the uncontrolled channel. Train for it, give users a "report a problem" action inside the application that sends the reference rather than the screen, and expect screenshots anyway.
Audit logs are different from debug logs. You are required to keep a record of who accessed what. That record necessarily names patients. It is a deliberate, access-controlled, long-retention store — and it is not the same system as the one your error messages go to. Conflating them means either losing the audit record or spraying the audit record through your observability vendor.
How to test it
- A test that builds a claim, triggers the error path, and asserts the log output contains the claim reference and does not contain the synthetic patient's name, date of birth or member identifier.
- The same for the exception reporter, with capture configured as it is in production.
- A grep of a day of real log volume in a staging environment for the shapes of things that should not be there: date patterns, long digit runs, the synthetic surnames from your fixtures.
- A check that no route in the application takes an identifier in its path or query string.
- An actual read of what the log aggregator is holding. Not the policy — the data. Search it for a fixture patient's surname and see what comes back.
What we do
We log references and never records: internal identifiers in the log lines, local variable capture off in the error reporter, a redaction filter at the boundary as a backstop, and a separate access-controlled audit trail for the access record that is genuinely supposed to name patients.
Building something that has to talk to a payer?
If any of the above is a problem you currently have, describe it and we will tell you what we would do about it.