博文地址:http://blog.csdn.net/ml5271169588/article/details/8871914
第二种方式加载log4j-contrl.propertes文件:
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class TestLog4j {
private static final transient Logger log = Logger.getLogger(TestLog4j .class);
public static void main(String[] args)throws InvalidKeyException, IllegalBlockSizeException, NoSuchAlgorithmException, UnsupportedEncodingException, BadPaddingException, NoSuchPaddingException {
PropertyConfigurator.configure(“src/log4j.properties”);
log.info(“记录日志信息,将在控制台输出”);
log.error(“可以记录错误信息,输出字体为控制”);
}
}