commons.logging版本1.1.1
log4j版本1.2.15
使用NetBeans IDE开发
-----------------------------------/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */package log4j.test2;/**
 *
 * @author Administrator
 */import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;
import org.apache.log4j.PropertyConfigurator;
//import org.apache.log4j.PropertyConfigurator;
public class TestLog{private static Log log = LogFactory.getLog(TestLog.class);public void test(){log.debug("111");log.info("222");log.warn("333");log.error("444");log.fatal("555");}public static void main(String[] args){PropertyConfigurator.configure(TestLog.class.getResource("log4j.properties"));//如果没有这句话,就不能自动找到log4j这个包,为什么呢?TestLog testLog = new TestLog();testLog.test();}}
==============================================
如果不加PropertyConfigurator.configure(TestLog.class.getResource("log4j.properties"));这句话,会发生错误。
错误如下:
log4j:WARN No appenders could be found for logger (log4j.test2.TestLog).
log4j:WARN Please initialize the log4j system properly.意思就是找不到log4j呗。这是怎么回事?
commons.logging不是可以自动搜索到log4j么?
而且网上说不用写commons-logging.properties。我这是什么情况啊?注:我另一个工程只用log4j.jar,不用commons-logging是可以成功实现的。