Video in progress

Why should you collect logs into a central system in microservices?

There are many services and they run in many copies, in containers; when a container goes away, the log inside it disappears too. A central system (ELK, Loki, etc.) keeps all the logs in one place and lets you search across them.

📖 Answer

In a monolith, you could ssh in and tail -f app.log. Now imagine 12 services, each in 3 copies, with Kubernetes pods recreated during a deploy. Which pod had the log you need, and does that pod even still exist?

A typical setup:

service -> stdout (JSON) -> agent (Fluent Bit / Promtail) -> Elasticsearch / Loki -> Kibana / Grafana

The service writes to stdout, not to a file; the container platform collects it. Spring Boot 3.4+ has structured logging built in:

logging.structured.format.console=ecs

The benefit of JSON logs is that you can filter by level, service, traceId, userId easily, with no need to split text with a regex.

One word of caution: don't write passwords, tokens, card numbers or personal data to logs. Many people have access to the central system, and logs are kept for a long time.