0
votes

I need to use slf4j with log4j2 in my application. But in all the blogs and tutorials it says - "We would need to exclude the dependency on spring-boot-starter-logging and add a dependency on spring-boot-starter-log4j2."

I understand internally spring-boot-starter-logging uses log4j/logback/spring-jcl etc but not log4j2. But my doubt is why we need to exclude 'spring-boot-starter-logging' , can't we just add 'spring-boot-starter-log4j2' and start using log4j2. ? Why to exclude 'spring-boot-starter-logging' ?

1

1 Answers

0
votes

spring-boot-starter-logging has a dependency on logback that will cause it to be included. If you also add spring-boot-sarter-log4j2 then you will end up with 2 SLF4J implementations present and will get a warning. SLF4J will choose whichever it finds first on the classpath.

If you remove spring-boot-starter-logging you can also just directly include the log4j dependencies you want. That way you can specify whatever version you want instead of what Spring says you must use.