Hem*_*roc 2 java spring slf4j maven log4j2
我正在通过SLF4J将我的一个应用程序更新到Log4J2并且我遇到了Spring的麻烦.
此外还有"正常"(正确)日志记录输出
2013-05-24 20:02:00,490 INFO [main] application.Application (Application.java:33) - Application started with arguments []
Run Code Online (Sandbox Code Playgroud)
我得到这样的台词
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
Run Code Online (Sandbox Code Playgroud)
在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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
Spring使用commons-logging框架进行日志记录.所以你应该commons-logging使用Maven排除从Spring中排除依赖,并添加maven依赖jcl-over-slf4j
| 归档时间: |
|
| 查看次数: |
3480 次 |
| 最近记录: |