Spring boot’s default logging uses Logback which is included as a transitive dependency. Spring Boot supports Log4j2 for logging configuration if it is on the classpath and Logback is excluded.
To configure Log4j2 with Spring Boot2, follow these two simple steps:
1. Log4j2 Maven Dependency
In fact, it is two steps change. First, remove spring’s default spring-boot-starter-logging starter dependency which excludes Logback from the classpath. Then add the spring-boot-starter-log4j2 starter dependency.
Spring will automatically configure log4j2 once it finds its jar files in the classpath. Now we have to add log4j2.xml or (log4j2.properties) in src/main/resources folder. That’s all.
Let me know if you face any problems in this spring boot log4j2 example.
Happy Learning !!
Comments
Subscribe
16 Comments
Most Voted
NewestOldest
Inline Feedbacks
View all comments
Lokesh Gupta
A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies.
An avid Sci-Fi movie enthusiast and a fan of Christopher Nolan and Quentin Tarantino.
Comments