Video in progress

What is structured logging, and how is a JSON log better than a plain text log?

In structured logging, every log record is an object with well-defined fields (usually JSON): level, message, traceId, orderId. The log system searches, filters and groups by these fields without regexes.

📖 Answer

A text log is convenient for people, not for machines:

2026-11-03 10:15:03 ERROR PaymentService - To'lov rad etildi orderId=881 amount=150000

To search "declined payments over 100,000" in Kibana or Loki, you write a regex, and if the format changes a little, the regex breaks.

In JSON:

{"ts":"2026-11-03T10:15:03Z","level":"ERROR","logger":"PaymentService",
 "message":"To'lov rad etildi","orderId":881,"amount":150000,"traceId":"4bf92f..."}

Now level:ERROR AND amount > 100000 is an ordinary query. A multi-line stack trace also stays inside one record, and the collecting agent doesn't split it up.

Starting with Spring Boot 3.4 this is built in:

logging:
  structured:
    format:
      console: ecs   # or logstash, gelf

In older versions you use logstash-logback-encoder. To add fields in code, the MDC or the encoder's StructuredArguments is handy.

Reading JSON locally is unpleasant, so people often split it by profile: text locally, JSON in prod.