调试依赖commons-logging日志的源码时,输出debug日志,springmvc,spring等等

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值