我才学log4j 有个搞不明白的地方 许多人说log4j不用PropertyConfigurator.configure();方法读取配置文件 直接用getLogger()方法就可以读取了  但我又看到很多文章 在web项目里面 要配置servlet 来读取配置文件 如下
public class Log4JInit extends HttpServlet {    
   public void init() throws ServletException{    
       String prefix = getServletContext().getRealPath("/");     
       String test = getServletContext().getRealPath("");     
       System.out.println(prefix);     
       System.out.println(test);     
          
       System.setProperty("webappHome", test);    
       String file = getServletConfig().getInitParameter("log4j-config-file");     
       System.out.println(prefix+file);     
       // 从Servlet参数读取log4j的配置文件     
        if (file != null) {     
         PropertyConfigurator.configure(prefix + file);     
           
       }    
   }    
}    那么到底要不要PropertyConfigurator.configure();  读取这一步呢  望各位高手告诉我 谢谢

解决方案 »

  1.   

    不需要PropertyConfigurator.configure()
    只要把配置文件命名为log4j.properties,然后放在WEB-INF/classes目录里就可以了。
      

  2.   

    这个貌似不用配置的吧?我没有配置,就直接把log4j.properties文件放到WEB-INF/classes下就可以了!
      

  3.   

    在web.xml中配置个毛啊,
    引入log4j的jar包,把它的配置文件log4j.properties直接丢到WEB-INF/classes目录下或src目录下就可以了