log4j初始化
第一种方案:配置文件放在/WEB-INF/目录下
1、创建一个serlvet使用容器加载时进行加载
配置log4j文件名称参数
在servlet中进行init方法中进行初始化
String realPath=this.getServletContext().getRealPath("/WEB-INF");
String log4j=this.getInitParameter("log4j");
String configFilename=realPath+File.separator+log4j;
PropertyConfigurator.configure(configFilename);
第二种方案:配置文件放在src目录下
String path=this.getClass().getClassLoader().getResource("/").getPath();
String configFilename:配置文件名称
PropertyConfigurator.configure(path+configFilename);
path:是src放到WEB-INF/classes/的目录,这个目录带斜杠