DELAPARRA
Index
Color
NL
Category: Observability

structured logging

Explained by Updated

What is structured logging?

structured logging: Logging machine-parseable key/value records (usually JSON) instead of free-form text, so logs can be queried and filtered. Structured logging means writing logs as machine-readable records with named fields, usually JSON, instead of free-form sentences. {"level":"error","msg":"payment failed","order_id":4821} instead of "Payment failed for order 4821". The difference shows when you search. Finding every failed payment over 100 euros, or every error for one customer, is a simple filter on fields, rather than a fragile text search.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about structured logging

What should you keep in mind with structured logging?

Keep message texts constant and put variable details in fields, so similar events can be grouped. Add context such as request ID, user ID and trace ID automatically, for example through a logging context in your framework. Laravel supports this with Monolog formatters and Log::withContext(). As always, keep passwords, tokens and unnecessary personal data out of log fields.

What does an example of structured logging look like?

{"level":"error","msg":"payment failed","order_id":4821,"latency_ms":250}

At a glance

CategoryObservability
Explained by
Updated

More Observability terms

All terms starting with S

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.