log4j入门

来源:互联网 发布:轩辕剑之天之痕mac 编辑:程序博客网 时间:2024/03/29 06:54

关于log4j的入门网上有很多,但是关于log4j.properties的路径却没有讲好。在找不到路径时就会有这个错误。

log4j:WARN No appenders could be found for logger (com.xxx.HelloLog4j).
log4j:WARN Please initialize the log4j system properly.

 

import org.apache.log4j.Logger;import org.apache.log4j.PropertyConfigurator;public class HelloLog4j {static Logger logger = LogFactory.getLogger(HelloLog4j.class); public HelloLog4j() {    }public static void main(String[] args) {PropertyConfigurator.configure("log4j.properties");//这句话是加入log4j.properties路径的,将放入工程的根目录即可System.out.print("a");logger.debug("addfg");}}