intermediate

Logs

Emit structured, correlated, redacted event records that explain what the service did and why it failed.

Logs explain discrete events: requests, decisions, failures, retries, and security-relevant activity. Production logs should be structured, correlated, redacted, and searchable.

					logger.info({
  event: 'order_created',
  orderId,
  requestId: req.headers['x-request-id'],
  userId,
  durationMs,
});
				

| Practice | Why | |----------|-----| | Structured JSON | Machine parsing and aggregation | | Request/correlation IDs | Trace one user action across services | | Level discipline | Signal vs noise | | Redaction | Prevent credential and PII leaks |

On interviews: log levels, context fields, correlation IDs, PII redaction, sampling, retention, and why unstructured console spam is not observability.

Common pitfalls: logging secrets or full payloads; logging everything at `info` drowns incidents.

The trade-off is diagnostic richness versus cost, privacy, and signal-to-noise ratio.

Checklist:

  • Emit structured logs.
  • Correlate requests across services.
  • Redact sensitive fields by default.
  • Define retention and access policies.