http://blog.csdn.net/u013516035/article/details/41686627
http://blog.csdn.net/sinat_30185177/article/details/73550377
注意 log4j.rootLogger = 输出位置
获取log4j.propeties文件的位置:String path = Log4j.class.getClass().getResource("/").getPath();
import java.util.Properties; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; public class Log4j { public static void main(String[] args) { String path = Log4j.class.getClass().getResource("/").getPath(); System.out.println(path); Logger logger = Logger.getLogger(Log4j.class.getName()); Properties props=new Properties(); PropertyConfigurator.configure(path+"/config/log4j.properties"); logger.debug("Debug ..."); logger.info("Info ..."); logger.warn("Warn ..."); logger.error("Error ..."); } }