What is structured logging and why use it?
masterTraditional logging captures information as a blob of text (level, message, metadata), which is often difficult for machines to parse and for humans to read when metadata is inlined.
Structured logging retains the original structure of data in a machine-readable format (like JSON). This allows for:
- Efficient querying: Easily find all records with a specific
correlation_idor count errors within a time range. - Better human readability: Presenting the human-readable message clearly while keeping ambient metadata (like
service,module, ortook) separate.
Example transformation:
Textual log:
[INF 2018-09-27T09:32:03Z basic] [service: database, correlation: 123] Operation completed successfully in 18ms
Structured log (JSON):
{
"ts": 1538040723000,
"lvl": "INFO",
"msg": "Operation completed successfully in 18ms",
"module": "basic",
"service": "database",
"correlation": 123,
"took": 18
}