I am trying to get log4j to work in the project I'm working on. I added the appropriate log4j dependencies to build.gradle and excluded the registration of the Spring starter launch so that it could work.
This worked fine when I used Maven as a build tool, but as soon as I switched to Gradle, it doesn't work at all (except registering with Spring's boot starter). Here are the dependencies in my build.gradle
dependencies { compile('org.springframework.boot:spring-boot-starter-data-jpa') compile('org.springframework.boot:spring-boot-starter-web'){ exclude module: 'org.springframework.boot:spring-boot-starter-logging' } compile('org.springframework.boot:spring-boot-starter-log4j') compile('org.springframework.boot:spring-boot-starter-data-rest') compile('org.springframework.boot:spring-boot-starter-actuator') compile('org.postgresql:postgresql:9.3-1101-jdbc41') compile('org.scala-lang:scala-library:2.10.4') testCompile('org.springframework.boot:spring-boot-starter-test') { exclude module: 'commons-logging' } providedCompile('org.springframework.boot:spring-boot-starter-tomcat') }
But, as you can clearly see in the dependency tree, spring-boot-starter-logging still exists. I guess this is the problem why the log is not working.
Here is the dependency tree:
+--- org.springframework.boot:spring-boot-starter-data-jpa: -> 1.2.1.RELEASE | +--- org.springframework.boot:spring-boot-starter:1.2.1.RELEASE | | +--- org.springframework.boot:spring-boot:1.2.1.RELEASE | | | +--- org.springframework:spring-core:4.1.4.RELEASE | | | \--- org.springframework:spring-context:4.1.4.RELEASE | | | +--- org.springframework:spring-aop:4.1.4.RELEASE | | | | +--- aopalliance:aopalliance:1.0 | | | | +--- org.springframework:spring-beans:4.1.4.RELEASE | | | | | \--- org.springframework:spring-core:4.1.4.RELEASE | | | | \--- org.springframework:spring-core:4.1.4.RELEASE | | | +--- org.springframework:spring-beans:4.1.4.RELEASE (*) | | | +--- org.springframework:spring-core:4.1.4.RELEASE | | | \--- org.springframework:spring-expression:4.1.4.RELEASE | | | \--- org.springframework:spring-core:4.1.4.RELEASE | | +--- org.springframework.boot:spring-boot-autoconfigure:1.2.1.RELEASE | | | \--- org.springframework.boot:spring-boot:1.2.1.RELEASE (*) | | +--- org.springframework.boot:spring-boot-starter-logging:1.2.1.RELEASE
Here is my log4j.properties file
log4j.rootLogger=INFO, fileout, CONSOLE PID=???? LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] log4j%X{context} - ${PID} %5p [%t] --- %c{1}: %m%n
UPDATE
I managed to fix jar file dependency exception. But the log is still not working, log4j.properties is also in the WAR distribution under the classes.
UPDATE 02
The problem worked with my IDE (STS)
spring spring-boot build.gradle gradle log4j
Switch
source share