Practical guides

Log errors without exposing sensitive data

Logs should help explain and resolve a situation. Recording every request detail creates volume and can copy information that should not leave its original workflow.

Go to the method

Useful, limited logs

Start with questions the logs should answer

List operational questions: is a form failing, is a process interrupted, has a backup been tested? Define the event, component, time and an appropriate correlation identifier. Avoid messages that collect text without helping identify an action.

Prepare synthetic examples of success, refusal and failure. An expected refusal should be distinguishable from an outage. Event names and levels should help the owner decide whether to investigate or monitor a trend.

Minimise recorded information

OWASP discusses data that should be excluded from logs, including passwords, access tokens and sensitive information. Review messages produced by your code as well as plugins, proxies and monitoring services.

Use an allowlist of fields instead of copying an entire request. A diagnostic identifier may suffice where a full enquiry message would be excessive. Test with synthetic markers, then search outputs for those markers to detect unintended collection.

Manage access, retention and volume

Document who can read logs and why. Confirm they are not served from a public address or made accessible by sharing tools. A diagnostic export needs the same access review as primary storage.

Choose retention according to the actual need and applicable context rather than copying another service’s duration. Arrange rotation, volume limits and deletion. A repeated failure should not fill a disk through unlimited logging.

Test the path from signal to action

Trigger a controlled failure in a test environment. Check the log, alert delivery, recipient and response procedure. An alert sent to an inbox no one checks does not form an operational process.

Group repetitions and follow signals that support decisions. After an incident, review what was missing and what was unnecessarily exposed. A useful deliverable connects an event with minimum data, an owner and an action.

Primary documentation : OWASP — Logging Cheat Sheet.

Acceptance matrix to adapt to your project

These proposed checks use synthetic cases. Decide the required behaviour with the team, record the result and assign unresolved gaps before release.

Test cases, expected outcomes and useful evidence
CaseExpected outcomeEvidence to retain
Known functional errorThe event explains the outcome and identifies the synthetic request.Event, time and correlation identifier across the relevant processing steps.
Synthetic sensitive markerThe marker is absent from fields that should exclude it.Search across every test log destination, including forwarded and archived copies.
Text containing a newlineThe field cannot manufacture an apparently valid extra event.Received value and the form actually recorded in the destination.
Unavailable logsApplication behaviour is understood and lost observability can be detected.Application result and observations made while log collection is interrupted.

Frequently asked questions

Should enquiry text be logged for diagnosis?

Not automatically. Identify minimum diagnostic fields and test with synthetic data first. A complete enquiry may be unnecessary for analysing a technical status.

Does a monitoring tool replace an owner?

No. It collects or sends a signal, but someone still needs to examine it using an agreed procedure. Test the entire chain with a controlled incident and verify the expected result.