Configure Logger using SLF4J in Spring MVC

Hello guys, Bushan here, Welcome back to B2 Tech. Today in this post, I will show you how to configure/implement Logger using SLF4J in Spring MVC/Java Application. So let’s begin,



Tools and Technologies used,

  • JDK 1.8.0_121
  • Eclipse Oxygen
  • SLF4J 1.7.12
  • Maven
  • Spring 4.2.1.RELEASE

Project Structure

Jar dependencies

Edit the pom.xml file and add slf4j dependencies in it as follows.



pom.xml

XML configuration file for SLF4J

Create a logback.xml file under the src/main/resources source folder and write the following code in it.



logback.xml

Console Appender – Writes the logs to either System.out or System.err
File Appender – Writes the logs to the File named in the <File> tag.

web.xml

spring-servlet.xml



HomeController.java

home.jsp

After running the application the console output and file D:/Logs/logger.log will look like as follows.



You can download the source code @
Love this post?

Help me to buy a cup of coffee/Support us by donating.
All the donations will be go to the website maintenance/improvement.

Fork it from Github Click here



About the author

Bushan Sirgur

Well, I am Bushan Sirgur from Banglore, India. Currently, I am working as a Software Developer in a Service Base Company. I am interested in JAVA/J2EE, Angular 2, JavaScript, jQuery, MongoDB.

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *