Course contentsShow
← Software Engineering
Lesson 1121 of 1,93334. Logging and ObservabilityFree lesson

What to Log

Identifying key events, state changes, errors, and business operations that should be captured in logs.

What to Log

You'll learn: how to identify which events and data points deserve a place in your application's logs.

The Signal in the Noise

Logging everything is like recording every breath you take—technically data, but mostly useless noise. Logging nothing is like driving blindfolded. The art is choosing what matters.

Events Worth Logging

State Changes

Log when important things transition: user sessions starting/ending, order status changes, service startup/shutdown. These mark the boundaries of meaningful operations.

Errors and Exceptions

Always log errors with sufficient context—the operation attempted, relevant IDs, error details. Your future self debugging at 2 AM will thank you.

Security Events

Authentication attempts (especially failures), authorization decisions, privilege changes, suspicious patterns. These are your audit trail and intrusion detection system.

Business Operations

Actions that have real-world consequences: payments processed, emails sent, reports generated, inventory updated. If it matters to the business, it matters to your logs.

Performance Indicators

Start and end of expensive operations, external API calls, database queries that exceed thresholds. Track what's slow before it becomes broken.

Key Decision Points

When your code chooses different paths based on configuration, feature flags, or runtime conditions, log which path was taken and why.

What NOT to Log

Don't log passwords, credit card numbers, personally identifiable information (PII), session tokens, or other sensitive data. Don't log inside tight loops that execute thousands of times per second—use sampling or metrics instead.

Think of logs as breadcrumbs through a forest. Drop them at intersections and landmarks, not every millimeter of the path.

Key Takeaway: Log state changes, errors, security events, business operations, and performance indicators—focus on events that help you understand system behavior, diagnose problems, and maintain audit trails.