Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
PHP Development

Being Able to Find Out What Happened

Last updated:

Logs are for answering questions later

The question is rarely “what error occurred?” It is “why did this customer's order end up in this state?” Answering that needs business events logged, not just exceptions.

A log full of stack traces and empty of business events tells you what broke and nothing about what happened.

What to log

  1. Business events — order created, payment taken, status changed, who did it
  2. Integration calls — what was sent, what came back, how long it took
  3. Scheduled job runs — start, finish, what was processed
  4. Authorisation failures, which indicate either a bug or an attack
  5. Errors, with enough context to reproduce them

Correlate with a request identifier

Generate an identifier at the start of each request and include it in every log line for that request, including any queued jobs it triggers.

That single practice turns log investigation from guesswork into filtering, and it costs almost nothing to implement.

Keep personal data out

  • Log identifiers, not names and addresses
  • Never log passwords, tokens or card details, even in error handlers
  • Redact before logging rather than after
  • Apply a retention period, automatically
  • Remember logs are in scope for data requests

Make them searchable

NeedRequires
Find one customer's journeyStructured logs with identifiers
Spot a patternAggregation across servers
Alert on somethingMachine-readable format
Investigate last monthRetention long enough
Prove what happenedImmutable storage

A log file that can only be read by tailing it on a server is a log nobody consults.

Frequently asked questions

How much should we log?

Enough to reconstruct what happened, not so much that finding it is impossible. Business events plus errors is usually the right level.

How long should logs be kept?

Thirty to ninety days for diagnostics; longer for anything serving as an audit record. Decide and apply it automatically.

Do we need a log aggregation service?

Once you have more than one server, effectively yes. Before that, structured files with a retention policy are adequate.

What about performance overhead?

Negligible at sensible volumes. Logging every database query in production is the exception and it is rarely warranted.

Keep reading

Cannot work out how a record got into that state?

That is a logging gap. Business event logging is a small change that answers most of these questions.

Book a free 30-minute call Get a project estimate WhatsApp us

Related services

What we build for problems like this one

Web DevelopmentCustom Software Development