http://blog.sina.com.cn/s/blog_54eb26870100uynj.html
到SLF4J官方网站:http://www.slf4j.org/codes.html#log4j_version
有如下说明:
The trace level was added to log4j in version 1.2.12 released on August 29, 2005. The trace level was added to the SLF4J API in version 1.4.0 on May 16th, 2007. Thus, starting with SLF4J 1.4.0, the log4j binding for SLF4J requires log4j version 1.2.12 or above.
从上面的说明可以看出,SLF4J用到了log4j的 trace 级别。
下载slf4j包, http://www.slf4j.org/dist/slf4j-1.6.4.zip
打开源码文件:
slf4j-1.6.4slf4j-log4j12srcmainjavaorgslf4jimplStaticLoggerBinder.java
发现有下面的定义:
import org.apache.log4j.Level;
.......
private StaticLoggerBinder() {
loggerFactory = new Log4jLoggerFactory();
try {
Level level = Level.TRACE;
} catch
(NoSuchFieldError nsfe) {
Util.report("This version of SLF4J requires
log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version");
}
}
从上面看出,如果org.apache.log4j.Level 没有TRACE属性,会报错“This version of SLF4J requires log4j version 1.2.12 or later. See also http://www.slf4j.org/codes.html#log4j_version”
这个异常是由于Level类没有静态属性TRACE抛出的,
因此解决办法有两个:
1、找到org.apache.log4j.Level中定义了TRACE属性的jar包,经过查找,log4j-1.2.15
这个版本有定义。
2、用SLF4j中自定义的org.apache.log4j.Level类,它重写了Level类。
我用的版本是slf4j-1.6.4.zip,可以从官方下载,里面有个jar包:log4j-over-slf4j-1.6.4.jar
把这个jar包放入web-info/lib下面即可,同时,要保证log4j-over-slf4j-1.6.4.jar优先装载。