Hemeroc
Hemeroc

Reputation: 2244

Spring not using log4j2.xml configuration over slf4j

I'm updating one of my applications to Log4J2 over SLF4J and I'm running into troubles with Spring.

Additionally to the "normal" (correct) logging output

2013-05-24 20:02:00,490 INFO  [main] application.Application (Application.java:33) - Application started with arguments []

I'm getting lines like this

Mai 24, 2013 8:02:00 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@5dfb3d5c: startup date [Fri May 24 20:02:00 CEST 2013]; root of context hierarchy

on System.err, so spring is not logging using my Log4J2 configuration.

These are my configuration files:

pom.xml

<slf4j.version>1.7.4</slf4j.version>
<log4j.version>2.0-beta6</log4j.version>

...

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>${slf4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>${log4j.version}</version>
</dependency>
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>${log4j.version}</version>
</dependency>

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appenders>
        <File name="file" fileName="error.log" append="true">
            <PatternLayout pattern="%t %-5p %c{2} - %m%n"/>
        </File>
        <Console name="console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/>
        </Console>
    </appenders>
    <loggers>
        <root level="all">
            <appender-ref ref="file"/>
            <appender-ref ref="console"/>
        </root>
        <logger name="org.springframework" level="error">
            <appender-ref ref="file"/>
            <appender-ref ref="console"/>
        </logger>
    </loggers>
</configuration>

Upvotes: 2

Views: 4387

Answers (1)

Maciej Walkowiak
Maciej Walkowiak

Reputation: 12932

Spring uses commons-logging framework for logging. So you should exclude commons-logging dependency from Spring using Maven exclusion and add maven dependency to jcl-over-slf4j

Upvotes: 6

Related Questions