commons-logging与slf4j一样是统一接口,但是用的多,spring-core依赖commons-logging,导致,spring的很多东西都是commons-logging,调试查看源码,输出debug,trace日志非常重要
添加下面两个文件到编译的classes根目录或resource目录等等
//commons-logging.properties
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
//simplelog.properties
org.apache.commons.logging.simplelog.defaultlog=debug
运行项目即可看到许多debug日志
看org.apache.commons.logging.impl.SimpleLog源码,就知道了,所有级别配置
public SimpleLog(String name) {
this.logName = name;
this.setLevel(3);
String lvl = getStringProperty("org.apache.commons.logging.simplelog.log." + this.logName);
for(int i = String.valueOf(name).lastIndexOf("."); null == lvl && i > -1; i = String.valueOf(name).lastIndexOf(".")) {
name = name.substring(0, i);
lvl = getStringProperty("org.apache.commons.logging.simplelog.log." + name);
}
if (null == lvl) {
lvl = getStringProperty("org.apache.commons.logging.simplelog.defaultlog");
}
if ("all".equalsIgnoreCase(lvl)) {
this.setLevel(0);
} else if ("trace".equalsIgnoreCase(lvl)) {
this.setLevel(1);
} else if ("debug".equalsIgnoreCase(lvl)) {
this.setLevel(2);
} else if ("info".equalsIgnoreCase(lvl)) {
this.setLevel(3);
} else if ("warn".equalsIgnoreCase(lvl)) {
this.setLevel(4);
} else if ("error".equalsIgnoreCase(lvl)) {
this.setLevel(5);
} else if ("fatal".equalsIgnoreCase(lvl)) {
this.setLevel(6);
} else if ("off".equalsIgnoreCase(lvl)) {
this.setLevel(7);
}
}
SimpleLog配置说明,从上面的源码可以看出来
配置默认级别,所有级别 all,trace,debug,info,warn,error,fatal,off
org.apache.commons.logging.simplelog.defaultlog=debug
配置包(com.dddd.test)的log级别
org.apache.commons.logging.simplelog.log.com.dddd.test=error