← DevOps Foundations
12 / 25
Lesson 12 — Structured logging
Logs that machines can read
A log line like disk full on web-1 is easy for a human but hard to search. Structured logging writes each entry as JSON with fixed fields — level, message, time, extra details — so tools like Grafana Loki or Elasticsearch can filter "all errors from web-1 in the last hour".
JSON.stringify({ level: "error", msg: "disk full" })
Why it matters: production logs are searched and alerted on, and that needs structure.
Want it another way?
Task
Make log() include the extra fields (spread ...extra) in the JSON, so host and disk appear.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.