Guides
Structured logging: a practical guide
What structured logging is, its benefits over plain text, a JSON log format that works, and the rules that keep structured logs searchable.
Tailcove Team
4 min read

Most applications start with logs like Payment failed for order 9182. They are easy to write and almost impossible to query reliably. Structured logging fixes that by separating what happened from the facts about it.
On this page11 sections
Benefits of structured logging#
- Search by field, not by text.
status>=500 route:/checkoutfinds exactly the lines you mean, where a text search also matches every line that happens to contain "500". - Answers, not only lines. Counts, averages and percentiles per host or route come straight from the fields, with no regular expressions to maintain.
- Grouping that works. A constant message with its details in fields lets the same event, or the same exception, be counted as one thing.
- Reliable alerts. An alert on
level:error service:paymentskeeps working when someone rewords a message. - Safer logs. Secrets live in known fields, so they are easy to drop or redact before they are stored.
Message plus context#
A structured log line has a short, stable message and a context object with the details:
{
"message": "Payment failed",
"level": "error",
"context": { "order_id": 9182, "gateway": "stripe", "amount_cents": 4200 }
}
The message stays the same every time this happens, so you can count it. The context changes, so you can filter on it.
A structured logging format: JSON#
JSON, one object per line (NDJSON), is the format almost every logger, shipper and log tool understands. A good line has a timestamp, a level, a constant message and the context as fields:
{"timestamp":"2026-09-30T10:15:00.003Z","level":"error","message":"Payment failed","order_id":9182,"gateway":"stripe","amount_cents":12900}
Keep the same field names across services, so one query works everywhere. Most logging libraries write this format once you pass the context as an array or object instead of building a string.
Keep messages constant#
Do not interpolate values into the message. Payment failed for order 9182 and Payment failed for order 9183 are two different strings to every search engine. Payment failed with order_id in context is one event you can count, alert on and group.
Name fields consistently#
Pick one convention and keep it across services:
snake_casekeys:order_id,user_id,duration_ms- Units in the name:
duration_ms,size_bytes,amount_cents - The same key for the same thing everywhere: not
uidin one service anduser_idin another
Consistent names are what make a query like user_id:42 work across your whole stack.
Log numbers as numbers#
Send "status": 503, not "status": "503". In Tailcove, numeric context fields support comparisons, so you can search for status>=500 or duration_ms>1000.
Use levels deliberately#
Levels are a filter you will use under pressure, so make them mean something:
| Level | Use it for |
|---|---|
debug |
Detail you only want while investigating |
info |
Normal, notable events: a deploy, a signup, a job finished |
warning |
Something unexpected that the app recovered from |
error |
A failed operation that needs attention |
critical |
The system or a key feature is broken |
Log exceptions, not strings#
When something throws, log the exception object rather than its message. Tailcove's clients render it as structured data (class, message, location and trace), which is what lets identical errors be grouped into a single issue.
Never log secrets#
Tokens, passwords, card numbers and full request bodies do not belong in logs. Redact them at the source; it is far easier than cleaning them up later.
Putting it together#
With structured logs in place, questions that used to need grep and patience become one query:
level:error gateway:stripe amount_cents>10000
Read the full query language reference to see everything you can ask.
FAQ#
What is structured logging?
Structured logging writes each log line as data, usually a JSON object, with a short constant message and the details in named fields, instead of a sentence with the details mixed into the text.
What are the advantages of structured logging?
You can search and filter by field, count and chart values without parsing text, group the same event or exception together, write alerts that do not break when wording changes, and redact secrets reliably.
What format should structured logs use?
JSON, one object per line, with a timestamp, a level, a message and the context as fields. Use the same field names in every service.
Do I need a special API for structured logging?
No. Most logging libraries already accept context as an object or array. To collect the lines in one place, send them to a log service as JSON, for example with Tailcove's HTTP API or one of its client libraries.
Put it into practice
Create a free Tailcove account and send your first log line in minutes.


