Course contentsShow
← System Design
Lesson 1137 of 1,91929. Observability: LoggingFree lesson

What is Structured Logging

Understanding structured logs as machine-readable key-value pairs instead of unstructured text strings.

What is Structured Logging

You'll learn how structured logging transforms logs from plain text into machine-readable data formats that enable powerful querying and analysis.

From Text Blobs to Data Structures

Traditional logging produces unstructured text strings like:

"User john@example.com failed login attempt from IP 192.168.1.50 at 2024-01-15 14:32:01"

While human-readable, parsing this programmatically requires fragile regex patterns and custom logic. Every slight format change breaks your parsing.

Structured logging formats each log entry as key-value pairs in JSON, XML, or similar formats:

{
  "timestamp": "2024-01-15T14:32:01Z",
  "level": "WARNING",
  "event": "login_failed",
  "user_email": "john@example.com",
  "ip_address": "192.168.1.50",
  "correlation_id": "req-abc-123"
}

Why This Matters

Think of structured logs as database records versus prose paragraphs. With structured logging, you can:

  • Query precisely: "Find all login failures from this IP in the last hour" becomes a simple filter on event="login_failed" and ip_address fields
  • Aggregate metrics: Count events by type, group by user, calculate percentiles automatically
  • Index efficiently: Log management systems can index each field separately
  • Correlate easily: Join logs across services using correlation_id without parsing strings

Modern logging libraries and platforms (like the standards you learned in lesson 1136) support structured formats natively, making it the default in production systems.

The Cost: Verbosity

Structured logs consume more storage than compact text strings, but the tradeoff is worth it for systems requiring operational insight at scale.

Key Takeaway: Structured logging uses machine-readable key-value pairs instead of unstructured text, enabling precise queries, automated analysis, and efficient indexing across distributed systems.