我正在通过SLF4J将我的一个应用程序更新为Log4J2,而且我遇到了Spring问题。
此外,还有“正常”(正确)日志记录输出
2013-05-24 20:02:00,490 INFO [main] application.Application (Application.java:33) - Application started with arguments []
我得到这样的行
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
在System.err上,所以spring没有使用我的Log4J2配置进行日志记录。
这些是我的配置文件:
的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>
答案 0 :(得分:6)
Spring使用commons-logging
框架进行日志记录。因此,您应该使用Maven排除从Spring中排除commons-logging
依赖项,并将maven依赖项添加到jcl-over-slf4j