commons-logging+log4j 进行ssm日志输出

啊啊啊 困扰很久的日志终于解决了,兴奋之余整理一下:

参考链接:commons-logging与logj的特点

这篇文章已经把commons-logging和log4j单独使用的方式以及各个的优缺点描述的很详细,但是这个并没有吧这两者结合起来,同时这个引入log4j.properties路径的问题需要看log4j日志加载,一下是我的日志测试类

public classLogProperties {

    public static Log log = LogFactory.getLog(LogProperties.class);
    public void log(){
        log.debug("Debug info.");
        log.info("Info info");
        log.warn("Warn info");
        log.error("Error info");
        log.fatal("Fatal info");
    }

    public void Info(Object obj){

    }

    public static void main(String[] args) {
        PropertyConfigurator.configure(ClassLoader.getSystemResource("config/log4j.properties"));
        LogProperties test = new LogProperties();
        test.log();
    }
}
对于commons-logging 只需要引入 commons-logging.jar,log4j只需要引入log4j.jar
关于二者的结合请看 commons-logging与log4j结合
测试的话,运用上面的log4j.properties即可,若是SPring项目 这需要
<context:property-placeholder file-encoding="utf-8" ignore-unresolvable="true" location="classpath:config/log4j.properties"/>加载这个配置文件(我的log4j.properties放在resources下面)
对于sql文的输出:需要在mybatis.xml中添加
<settings>
    <setting name="mapUnderscoreToCamelCase" value="true"/>  //java的驼峰结构
    <setting name="logImpl" value="LOG4J"/>  //指定日志的输出以log4j
</settings>




 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值