INTRO
When production misbehaves, you grep - or you query. Structured logs turn “find this user’s failed checkout” from archaeology into a filter. I standardize fields: `level`, `time`, `msg`, `requestId`, `userId`, `route`, `durationMs`.
One JSON object per line
Log aggregators expect newline-delimited JSON. Human readability in prod matters less than parse reliability.
Include correlation ids from edge (load balancer) or generate at entry middleware and propagate to downstream calls.
code-snippet.typescript
logger.info({
msg: 'order_created',
requestId: req.id,
userId: req.user?.id,
orderId: order.id,
durationMs: Date.now() - started,
})Redact secrets and PII by policy
Never log full card numbers, passwords, or raw JWTs. Redact keys matching `password`, `authorization`, `cookie` at the serializer level.
Sampling debug logs in hot paths prevents cost explosions.
KEY TAKEAWAYS
“Use structured logs with stable field names.”
- 02
Propagate requestId across services.
- 03
Redact sensitive keys centrally - not ad hoc in each route.
CONCLUSION
Closing thought
Logging is your cheapest observability. Structure it once, and incidents get shorter every time. Ready to talk scope? Use Contact — or browse Services for fit.
CONTINUE
Related pages
UP NEXT
Production Observability for Next.js and Node.js
A practical observability baseline for product teams: request IDs, structured logs, latency/error dashboards, and trace links that speed up root-cause analysis.
Read next article