Spring boot logging log4j2 example
What you will learn here about Spring boot logging
- spring boot logging log4j2 example
- spring boot log4j2 dependency
- spring boot log4j2 properties
- Spring boot logging in file
It is very easy to add logging functionality in spring boot. Here we are going to see how to add logging functionality in spring boot using log4j. Please click on below link to download the sample project of logging in spring boot using log4j.
Download spring boot logging log4j2 example project (449 downloads)
Spring boot logging log4j2 example
Please follow the following steps to know how to add log in spring boot application using log4j2.
1)Add logging dependency in pom.xml file which is shown below. you will get dependencies in above sample project
2)Create properties file and add configurations
- First create log4j2.properties file under resources folder which is shown below
- Add properties in log4j2.properties file which you will get in above sample project
- Please replace logger.file.name with the your application root package which is shown below
3)Create rest controller and start logging in file
- First create new package and then create new class which is shown below in step 1
- Create logger Object which is shown below in step2
- Start logging using logger object which is shown below in step 3
4)Run the spring application
- Open your Spring boot application
- Run the application
5)Make Get request from browser and check the logs
- Open the browser and make get Request for /home URL which is shown in step 1
- Now please go to eclipse and right click on project and please click on Refresh which is done in step 2
- Now you should able to see logs folder which is shown in step 3. If you are able to see means you are able to logging logs using log4j successfully.