Good logging enables debugging, monitoring, and auditing. This guide covers logging strategies for production applications.
Structured Logging#
Use JSON for machine-readable logs:
Loading code block...
Log Levels#
Loading code block...
Request Context#
Loading code block...
What to Log#
- Request/response metadata (not sensitive data)
- Error details with stack traces
- Business events (user actions, transactions)
- Performance metrics
- Security events (auth failures, permission denied)
What NOT to Log#
- Passwords and secrets
- Credit card numbers
- Personal health information
- Full request bodies with sensitive data
Log enough to debug issues, but protect user privacy.