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>




 
  


你可能感兴趣的:(web框架)