How to Set Up ELK Stack with Spring Boot for Centralized Logging Purposes?
Last Updated :
20 Aug, 2024
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
Add Web dependencies to the project path > Generate project POM file or. Attached generated (build.gradle) file.
pom.xml file:
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
Copy the Elastic User Password > Save the Enrollment Token
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
Go to the URL > Copy it and paste it cmd > Put the Enrollment stolen number like "Set up Elastic Search" > Click on Configure Elastic
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.
- 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
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
How to Setup Central Logging Server with Rsyslog in Linux This article will show us how to use Rsyslog to set up Linux as a centralized logging service. When managing logs from various systems, a centralized Rsyslog setup is advantageous. All log entries from client servers will be sent to the host server, which will allow them to be monitored and preserve
4 min read
Centralized Logging for Microservices In a microservices architecture, applications are decomposed into smaller, independently deployable units. This architecture offers numerous advantages, such as improved scalability and flexibility, but it also introduces complexities, particularly in monitoring and debugging. One of the critical ch
6 min read
How to Set the Logging Level with application.properties? In Spring Boot, logging is crucial for monitoring, debugging, and troubleshooting Java applications. Spring Boot provides a convenient way to configure logging levels using properties files, particularly the application.properties file of the Spring application. This allows developers to control the
5 min read
Setting the Log Level in Spring Boot When Testing When developing applications with Spring Boot, controlling log output is essential for diagnosing issues and understanding application behavior, especially during testing phases. Setting the log level allows developers to specify the type of information logged by the application, ranging from verbos
4 min read
How to Create a Spring Boot Project? Spring Boot is built on top of the spring and contains all the features of spring. It is one of the most popular frameworks for building Java-based web applications and microservices. It is a favorite among developers due to its rapid, production-ready environment, which allows developers to focus o
6 min read
Spring Boot Integration With MongoDB as a Maven Project MongoDB is a NoSQL database and it is getting used in software industries a lot because there is no strict schema like RDBMS that needs to be observed. It is a document-based model and less hassle in the structure of the collection. In this article let us see how it gets used with SpringBoot as a Ma
4 min read