Open In App

How to Set Up ELK Stack with Spring Boot for Centralized Logging Purposes?

Last Updated : 20 Aug, 2024
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

A centralized logging system is crucial for tracking and debugging the internal workings of distributed systems. The ELK stack—comprising Elasticsearch, Logstash, and Kibana—serves as an effective toolkit for implementing these operations. When combined with Spring Boot's developer-friendly features, it forms a robust foundation for application log analysis and visualization. While the production-ready configuration may be more complex and tailored to specific needs, setting up and familiarizing yourself with the ELK stack locally is highly beneficial for understanding each major component.

In this article, we'll explore the initial steps to set up the ELK stack with Spring Boot for centralized logging on a local system.

Understanding of ELK

Technically, the acronym ELK stands for Elasticsearch, Kibana, and Logstash in system configuration. This effective open-source software stack is designed for log analysis, visualization, and centralized logging across various machines. The powerful ELK stack allows users to collect internal logs from all their systems and applications, analyze them, and create visualizations for infrastructure and application monitoring, quicker troubleshooting, security analytics, and more.

  • Elasticsearch: It is a distributed search and analytics engine used for data storage and indexing. Elasticsearch can quickly and efficiently search, aggregate, and analyze large volumes of data within the system.
  • Logstash: This is a data processing pipeline that gathers data from various sources, processes it, and sends it to Elasticsearch for indexing or formatting. Logstash can handle a variety of structured data formats, including logs, metrics, and other event data.
  • Kibana: An online application for exploring and visualizing data, Kibana works in conjunction with Elasticsearch. It offers a user-friendly interface for searching, analyzing, and displaying Elasticsearch data, with a wide range of dashboards, tools, and visualizations to help extract meaningful insights.

These three components form the ELK stack, a commonly used solution for internal log management, monitoring, and troubleshooting across various systems and applications.

Start with a Spring Boot Application

Now, let's create a Spring Boot application as a basic setup step. Follow the below instructions for better implementation

First, Go to Spring Initializr officially > Select a preferred language (probably Java) > Add the details and dependency

Spring Initializr


Add Web dependencies to the project path > Generate project POM file or. Attached generated (build.gradle) file.

Project Metadata


pom.xml file:

pom.xml


Setting up ELK Stack with Spring Boot for Centralized Logging Purposes

From the Elastic official website, get the required packages that are compatible with your operating system. Users need to pay attention to the installation guidelines provided for every part before installing it. Now, follow the below Step to set up the ELK stack with Spring Boot properly for Centralized Logging.

Step 1: Set up the Elastic Search system

  • Officially, Download and Unzip Elasticsearch system > Go and Select the command "elasticsearch-<version>-<os>-<system-type>\elasticsearch-<version>\bin"
  • Open cmd > Run the below command
.\elasticsearch.bat
elastic_search


Copy the Elastic User Password > Save the Enrollment Token

Verify_process

Step 2: Set up the Kibana system

  • Officially, Download and Unzip Kibana system > Go and Select the command "elasticsearch-<version>-<os>-<system-type>\elasticsearch-<version>\bin"
  • Open cmd > Run the below command
.\kibana.bat
Kibana_download


Go to the URL > Copy it and paste it cmd > Put the Enrollment stolen number like "Set up Elastic Search" > Click on Configure Elastic

Kibana_Code

Step 3: Set up the Logstash system

  • Officially, Download and Unzip Logstash system > Go and Select the command "logstash-<version>-<os>-<system-type>\logstash-<version>\config"
  • Click and Open "log stash-sample. conf" > See the console.
Structure
  • Replace the <Log File Full Path> with the system log file location
  • Replace <Elastic Search Password> with the internal structured password
  • Process and go to the "log stash-<version>-<os>-<system-type>\logstash-<version>\bin" directory system > Write the Command line
logstash.bat -f ./config/logstash-sample.conf
LogController.java

Conclusion

By following these steps, we have successfully configured Spring Boot with the ELK stack for centralized logging. This setup allows you to efficiently collect, store, and analyze internal system logs from your Spring Boot applications. This powerful combination enhances real-time monitoring, functional troubleshooting, and insight-gathering capabilities within your application environment.


Similar Reads