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

What is Structured Logging

Learn how structured logging uses machine-readable formats instead of plain text strings for better querying and analysis.

What is Structured Logging

You'll learn how structured logging replaces plain text messages with machine-readable formats for better querying and analysis.

The Problem with Plain Text Logs

Traditional logging writes messages as unstructured text strings:

"User login failed for johndoe at 2024-01-15 10:23:45"

This works for human reading, but it's difficult for machines to parse. If you want to find all failed logins for a specific user, you need string matching or regex patterns—error-prone and slow.

Structured Logging: Data, Not Just Text

Structured logging formats log entries as key-value pairs or objects, typically in JSON:

{
  "timestamp": "2024-01-15T10:23:45Z",
  "level": "warning",
  "event": "login_failed",
  "user": "johndoe",
  "ip_address": "192.168.1.100"
}

Now each piece of information has a named field. You can query event="login_failed" AND user="johndoe" directly.

Why This Matters

Think of it like the difference between writing notes in a paragraph versus filling out a form. The form has labeled fields—you can instantly find the "Name" field in any form. The paragraph requires you to read and interpret context each time.

Structured logs enable:

  • Powerful querying: Filter by exact field values without pattern matching
  • Aggregation: Count events by user, calculate average response times
  • Alerting: Trigger on specific field values
  • Correlation: Link related events across services using request IDs
  • Dashboards: Automatically visualize trends from structured data

Modern log aggregation tools expect structured formats—they can automatically index fields and make them searchable.

Key Takeaway: Structured logging replaces human-readable text strings with machine-parseable formats (typically JSON), enabling powerful querying, filtering, and analysis across large-scale systems.