Problem
Free-text logs are hard to query and vary between services. During incidents, engineers grep through inconsistent messages and cannot reliably correlate events across components.
Emit logs as consistent, machine-readable events that can be searched, aggregated, and correlated.
Free-text logs are hard to query and vary between services. During incidents, engineers grep through inconsistent messages and cannot reliably correlate events across components.
Structured logging treats each log line as data. Once events share a schema, logs become a queryable dataset instead of a pile of text, and correlation across services becomes straightforward.
A logging library formats each event as JSON with mandatory fields and attaches request-scoped context automatically, for instance trace identifier, user or tenant identifier, and route. Developers log an event name and attributes rather than interpolated sentences. Log levels reflect operational meaning, and debug output is disabled or sampled in production. Agents ship logs to a central platform where parsing is trivial because the structure is already present, and indexes are built on the most queried fields.
{
"timestamp": "2026-10-31T12:00:00.123Z",
"level": "error",
"service": "checkout",
"event": "payment_failed",
"trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
"tenant_id": "t-1042",
"error_code": "card_declined",
"duration_ms": 312
}
Teams adopt this approach when multiple services produce logs that must be searched together; incident response depends on filtering by request, user, or tenant. It is a poor fit when throwaway scripts where human-readable output is sufficient, or when environments with extreme storage constraints and no central aggregation. The central tensions are detail vs storage cost; developer readability vs machine usability; schema strictness vs team flexibility. The main benefits are that it delivers: queryable fields instead of text parsing; consistent correlation across services; easier alerting and metrics derivation; better tooling support. The main costs to budget for are: verbose output increases storage cost; less readable locally without tooling; schema drift without governance; risk of logging sensitive structured data. Governance typically looks like this: platform defines the log schema and library; teams add domain fields. Expect adoption cost to be low: library adoption and conventions, and a best fit for any team running more than one service. Critics point out that teams often log too much and still miss the one event they need, and that structured does not guarantee meaningful: poorly chosen fields create expensive noise. Treat these concerns as design inputs, and revisit the decision as traffic, team size, and failure history change.