Log Management in Spring Boot Applications with Elastic Stack
Tags: elasticstack, kibana, logstash, springboot
Published: 2020-01-29 22:22:52



Today, when we code our applications, we often ignore the fact that the codes we write or a tool we use behave differently than it should be. The reason for this is that, for whatever reason, we know that the application will give an error or warning in an exceptional situation and that the problem can be found in log files. Therefore, as developers, we rely heavily on log files when developing applications. Debugging, observing application behavior; are essential parts of any stage of the application.

Log management applications reduce the great time spent on logs. Features such as adding filters to the logs and searching in the log files, thanks to the management applications, save us from getting stuck with the logs and save time for us to solve the problem.


**Why is Log Management Necessary?**
* It allows us to observe the behavior of our log management application.

* With log management tools, it is ensured that log records can be observed by people who are not experienced in software.

* Log management applications are required for logs to be stored and analyzed as needed.

* Log management applications allow system administrators to define failed login attempts or warnings specific to suspicious processes.

![docker_desktop](https://miro.medium.com/max/2932/1*J-P2NN1JE2uYK9uNnsVkfA.png)

**Let's start**

First, let's clone the project from [GitHub](https://github.com/gunerkaanalkim/springbootelasticstack). I will cite this project for the rest of the article.

**Database Configuration**

The part that runs the database is the **db** service in **docker-compose.yml**. Various environment variables are used here. You can edit them as desired from the .env file located in the root of the project. These environment variables are also included in the **application.yml** file of the project, they work with their default values if no external variables are given.

![application_yml_db](https://miro.medium.com/max/4044/1*n6Lq5zcWLjneuftnRz2RGw.png)

**Elasticsearch Configuration**

Elasticksearch runs with the **elasticsearch** service in **docker-compose.yml**. We also see that it will run with the names single-node and **elastic-search-cluster** in the **containers/elasticsearch** folder located in the project root directory.

**LogStash Configuration**

LogStash runs with the **logstash** service in **docker-compose.yml**. There is also a configuration file in the **containers/logstash** folder located in the project root directory.

_The point to be considered here is the location of the log file in the **input** section. This file path is then made in **docker-compose.yml** with the logging.file information in the **application.yml** file of the application._

![](https://miro.medium.com/max/2120/1*kZl_SV2uUhwLyLuUnDU6xg.png)
![](https://miro.medium.com/max/2700/1*B0A4lEdqIMmMkhcd_oyzWA.png)

_In the Output section, there is index information. With this index information, we will configure on kibana in the next step._

**Kibana Configuration**

Kibana runs with the **kibana** service in **docker-compose.yml**. There is also a configuration file in the **containers/kibana** folder located in the project root directory. After all the processes are completed, we can observe our logs by going to _http://localhost:5601_ and creating a new index with the index name specified in the output configuration of LogStash.
![](https://miro.medium.com/max/6532/1*tZBYmS0asjLzZxZxKBamrg.png)