Record diagnostic context
Include timestamp, severity, service and release version, request or trace identifier, and a concise event description. Add relevant operation names and durations so slow paths can be investigated without dumping full payloads.
Use consistent fields and distinguish expected validation failures from unexpected errors. Redact authorization headers, tokens, passwords, and sensitive user values before data reaches the logging system.
Control retention and access
Choose retention based on troubleshooting needs and applicable policy, and restrict access to people who need it. Logs can reveal architecture, identifiers, or usage patterns even when message bodies are absent.
Alert on actionable patterns such as sustained error rates or repeated startup failures, not on every isolated event. Test that correlation identifiers appear across the application and any connected background jobs.