for one of my applications I have a problem with log4j and appenders for the spring 3. The exact error warning message is "log4j:WARN No appenders could be found for logger (org.springframework.test.context.support.DependencyInjectionTestExecutionListener). log4j:WARN Please initialize the log4j system properly.".
I read the information about configuration of spring with log4j but I don't have any success to overcome that problem. Logging through log4j is working but with that WARN message.
This is my pom configuration for log4j and spring - it's rather long configuration.
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.org.apache.commons.logging</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>com.springsource.slf4j.log4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${slf4j.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.log4j</groupId>
<artifactId>com.springsource.org.apache.log4j</artifactId>
<version>1.2.15</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
Plus I have one more logging related - exclusion for commons-logging for spring-core and spring-context.
This is web.xml configuration:
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:META-INF/properties/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
This is the log4j.properties configuration:
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.rootLogger=DEBUG, stdout, R
log4j.appender.R.File=application.log
log4j.appender.R.MaxFileSize=700KB
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.logger.mongo=DEBUG,console
I'm looking for more info-source where I can find a way to fix that.
And here is the solution - thanks for the responses, there was one answer that drive me to the right direction but it seems it is deleted by the author.
Solution: 1. Move the log4.properties file from src/main/resources/META-INF/properties/log4j.properties to src/main/resources/log4j.properties 2. Change log4j configuration in web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath*:log4j.properties</param-value>
</context-param>
And the problem is fixed :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With