3. 测试代码:
[java]
/**
* @author oscar999
* @date 2013-8-1
* @version V1.0
*/
package com.oscar999.log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestLogCom {
static Log log = LogFactory.getLog(TestLog.class);
public static void main(String[] args) {
log.debug("Here is some DEBUG");
log.info("Here is some INFO");
log.warn("Here is some WARN");
log.error("Here is some ERROR");
log.fatal("Here is some FATAL");
}
}
/**
* @author oscar999
* @date 2013-8-1
* @version V1.0
*/
package com.oscar999.log;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class TestLogCom {
static Log log = LogFactory.getLog(TestLog.class);
public static void main(String[] args) {
log.debug("Here is some DEBUG");
log.info("Here is some INFO");
log.warn("Here is some WARN");
log.error("Here is some ERROR");
log.fatal("Here is some FATAL");
}
}
除了使用log4j 之外, 还可以配置
-org.apache.commons.logging.impl.Jdk14Logger 使用JDK1.4。
-org.apache.commons.logging.impl.Log4JLogger 使用Log4J。
-org.apache.commons.logging.impl.LogKitLogger 使用 avalon-Logkit。
-org.apache.commons.logging.impl.SimpleLog common-logging自带日志实现类。它实现了Log接口,把日志消息都输出到系统错误流System.err 中。
-org.apache.commons.logging.impl.NoOpLog common-logging自带日志实现类。它实现了Log接口。 其输出日志的方法中不进行任何操作。
总结
以上有一条
3) 否则,查看classpath中是否有Log4j的包,如果发现,则自动使用Log4j作为日志实现类;
项目同时导入log4j 和commons-logging的jar 包, 不需要配置commons-logging.properties ,只需要在classpath中配置 log4j.properties就可以使用log4j的方式记录日志。这也是目前用的比较多的记录日志的方式。