Centralized Logging with ELK Stack (Elasticsearch, Logstash, Kibana)

In a microservices architecture, logging becomes more complex as logs are scattered across multiple services. This makes debugging and monitoring challenging.

Centralized Logging with ELK Stack solves this problem by aggregating logs from all services into a central platform, enabling real-time visualization and search.

In this guide, youโ€™ll learn how to integrate Spring Boot microservices with the ELK Stack โ€” Elasticsearch, Logstash, and Kibana โ€” for powerful centralized logging.

Centralized Logging with ELK Stack

๐Ÿ“ฆ Stack Overview

  • Elasticsearch: Stores structured log data
  • Logstash: Parses and transports log data
  • Kibana: Visualizes log data with dashboards

๐Ÿงฐ Step 1: ELK Stack Setup Using Docker

Create a docker-compose.yml:

โš™๏ธ Step 2: Logstash Configuration (logstash.conf)

๐Ÿ“ Step 3: Spring Boot Logback Configuration

Youโ€™ll use Logback + Logstash encoder in your Spring Boot apps.

๐Ÿ”ง Add dependencies to pom.xml:

๐Ÿ“„ logback-spring.xml Configuration:

๐Ÿง‘โ€๐Ÿ’ป Example Microservice Logging

๐Ÿงช Step 4: Run Everything

  1. Run docker-compose up
  2. Run your Spring Boot microservice
  3. Visit Kibana UI at http://localhost:5601
  4. Create an index pattern:
    springboot-logs-*

Now you can search and visualize logs.

๐Ÿง  Best Practices

  • ๐Ÿงพ Use structured JSON logs
  • ๐Ÿ›ก๏ธ Mask sensitive data before logging
  • โš ๏ธ Set log levels wisely (ERROR, INFO, DEBUG)
  • ๐Ÿ“ Separate environments by index (e.g., logs-dev-*, logs-prod-*)

๐Ÿ“ˆ Benefits of Centralized Logging with ELK Stack

  • ๐Ÿ” Full-text search of logs with Kibana
  • ๐Ÿง  Easy debugging and traceability across microservices
  • ๐Ÿงฉ Seamless integration with Spring Boot via Logback
  • ๐Ÿ“Š Real-time dashboards and alerts

๐Ÿ Conclusion

Implementing Centralized Logging helps unify and analyze logs across all your microservices. With structured logging, searchable indexes, and visual dashboards, the ELK stack provides visibility and observability into your applications.