Skip to Content
Tech PrinciplesTechnical ResourcesApplicationLogging

Logging 📄

Omit Sensitive Data

Never log sensitive data like credentials, personal info, or financial data.

  • Scrub PII, PHI, and PCI data from application code and logs
  • Classify data correctly based on sensitivity
  • Sanitize data before logging

Sensitive data through correlation

Combinations of non-sensitive fields can reveal sensitive data through correlation. For example, logging a customer’s date of birth, postal code, and purchase amount could help expose their identity by matching it against voter registration data which contains date of birth and zip code

Use Log Levels

Leverage log levels like DEBUG, INFO, WARN, ERROR appropriately:

  • DEBUG for verbose tracing during development
  • INFO for tracking key events in production
  • WARN for undesired but recoverable conditions
  • ERROR for critical non-recoverable errors

Right-sized logging improves signal/noise ratio.

Leverage Mapped Diagnostic Context

MDC allows associating contextual info with logs:

  • Add request IDs to correlate logs end-to-end
  • Include customer IDs, device IDs for analysis
  • Helps group, filter and analyze related logs

MDC provides crucial context for a request, event, or message.

Control Log Volume

Too many logs impacts costs and slows analysis.

  • Only log essential data based on traffic
  • Increase sampling rates if volumes overwhelm storage
  • Delete logs after a retention period

Strike a balance between intelligence and frugality.

Enable Debugging

Logs should provide debugging capabilities:

  • Ensure useful logs in all environments
  • No verbose traces in production
  • Enable on-demand verbose logging

Debugging saves precious time during incidents.

Last updated on