Blog

Log Like Your Job Depends On It Because It Does

leave breadcrumbs
Dark cyberpunk room with neon breadcrumb trail leading to a hidden software bug

If your production debugging strategy is System.out.println, I hope your users are patient and your manager is forgiving.

Logs are not diary. Logs are evidence trail.

Structured Logs

String logs are hard to query.

Bad:

log.info("User " + userId + " paid " + amount);

Better with structured fields, depending on logging stack:

log.info("payment_authorized accountId={} amount={} currency={}",
    accountId, amount, currency);

Best when emitted as JSON with fields your platform indexes.

{
  "event": "payment_authorized",
  "accountId": "acc-123",
  "amount": "10.00",
  "currency": "EUR",
  "correlationId": "req-abc"
}

Correlation ID

One user request crosses API, ledger, risk, notification. Without correlation id, you search logs like archaeologist.

Use MDC in Java.

class CorrelationFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest request,
                                    HttpServletResponse response,
                                    FilterChain chain) throws IOException, ServletException {
        String correlationId = Optional.ofNullable(request.getHeader("X-Correlation-Id"))
            .orElse(UUID.randomUUID().toString());
        MDC.put("correlationId", correlationId);
        try {
            response.setHeader("X-Correlation-Id", correlationId);
            chain.doFilter(request, response);
        } finally {
            MDC.clear();
        }
    }
}

Cleanup matters. Thread pools reuse threads.

Log Levels

ERROR means action needed. WARN means suspicious but handled. INFO means business-important state transition. DEBUG is for development detail.

If everything is ERROR, nothing is ERROR.

Do Not Leak Secrets

Never log card numbers, passwords, tokens, full personal data. Mask aggressively. Compliance people are not amused by your convenient debug line.

Final Rule

When incident happens, logs should answer: who, what, when, where, correlation id, state transition, and failure reason.

Log like tired engineer at 3 AM depends on it. Because eventually it is you.