现在的位置: 首页 > 综合 > 正文

commons-logging-1.1.1日志接口用法

2018年05月28日 ⁄ 综合 ⁄ 共 988字 ⁄ 字号 评论关闭

  前言 
    通过commons-logging-1.1.1架构来实现log4j,sl4j,jdk的log等日志管理系统的接口.使log系统更容易切换 

一 包 
commons-logging-1.1.1.jar 
log4j-1.2.16.jar 

二 src下的文件 
log4j.properties 
log4j.rootLogger=DEBUG,appender1,appender2 
log4j.appender.appender1=org.apache.log4j.ConsoleAppender 
log4j.appender.appender1.layout=org.apache.log4j.PatternLayout 
log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n 
# 立即输出 
log4j.appender.appender1.immediateFlush=true  

commons-logging.properties 
# 此配置文件可以省略,默认就是使用的log4j 
# 必须要有commons-logging-1.1.1.jar; 
# commons-logging-adapters-1.1.1.jar,commons-logging-api-1.1.1.jar为可选 
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger 

三 调用 

Java代码  收藏代码
  1. package com.phl;  
  2.   
  3. import org.apache.commons.logging.Log;  
  4. import org.apache.commons.logging.LogFactory;  
  5.   
  6. public class Test {  
  7.     private static Log log = LogFactory.getLog(Test.class);  
  8.   
  9.     public static void main(String[] args) {  
  10.   
  11.         log.debug("hello commons-logging!");  
  12.     }  
  13.   
  14. }  

抱歉!评论已关闭.