How to configure Spring 3 with SLF4J over LOG4J2 using Log4jConfigurer?

I am trying to configure my application to use SLF4J with log4j2 for logging. The application uses Spring 3. The console logger is working but none of the Rolling appenders seems to be logging anything.

Here is how application logging is configured :

  • pom.xml

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>3.2.18.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>3.2.18.RELEASE</version>
        <type>jar</type>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-slf4j-impl</artifactId>
        <version>2.11.0</version>
    </dependency>
    <dependency>
    
  • web.xml

    <listener>
           <listener-class>
               org.springframework.web.util.Log4jConfigListener
           </listener-class>
    </listener>
    
  • Application.xml

log4j properties :

    log4j.rootLogger=DEBUG, CONSOLE

log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[%d{ISO8601} EST] %X{sessionId} %X{requestTokenId} %X{clientIP} %p %m%n

log4j.appender.TEST_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.TEST_APPENDER.File=a.log
log4j.appender.TEST_APPENDER.MaxFileSize=10MB
log4j.appender.TEST_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.TEST_APPENDER.layout.ConversionPattern=[%d{ISO8601} EST] %X{sessionId} %X{requestTokenId} %X{clientIP} %p %m%n
log4j.appender.TEST_APPENDER.MaxBackupIndex=8
log4j.appender.TEST_APPENDER.Threshold=DEBUG

log4j.logger.com.abhishek=DEBUG, CONSOLE, TEST_APPENDER

application xml :

<bean id="log4jInitialization" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
        <property name="targetClass" value="org.springframework.util.Log4jConfigurer" />
        <property name="targetMethod" value="initLogging" />
        <property name="arguments">
            <list>
                <value>${config.dir}/log4j.properties</value>
            </list>
        </property>
    </bean>

logging code :

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOGGER = LoggerFactory.getLogger(Test.class);
LOGGER.debug("Testing...");