Pcornel
Observability · Logs

Structured Logging

Cheat sheet · https://pcornel.dk/topic.php?topic=6207

Back to the Topic

Answer

Structured logging writes logs as key-value data (usually JSON) instead of free text, so fields can be filtered, aggregated and correlated.

Remember

Use consistent field names (timestamp, level, service, message, trace_id). Log the event once with context instead of many lines. Never log passwords, tokens or full card data.

First checks

  • tail -1 app.log | jq . — first check for this topic
  • curl -s localhost:9090/-/ready — Prometheus ready
  • curl -s 'localhost:9090/api/v1/query?query=up' — scrape targets up/down
  • promtool check config prometheus.yml — config valid

Verify in this order

event + context → JSON line → parsed fields → queries

Where it usually breaks

Multi-line stack traces break line-based collectors unless joined.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6207

Confirmation

Confirm action

Continue?