Re: Eclipse, log4j, etc.

Ed Thompson <[email protected]> Sun, 08 Feb 2004 13:48:32 -0500
Newsgroups gmane.comp.web.maverick.general
Organization The Thompson's
Message-ID <[email protected]>
I have the following in my web.xml:

   <servlet>
     <servlet-name>log4j-init</servlet-name>
     <servlet-class>org.ed4becky.mComics.Log4jInit</servlet-class>
     <init-param>
       <param-name>log4j-init-file</param-name>
       <param-value>WEB-INF/log4j.properties</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>

org.ed4becky.mComics.Log4jInit looks like this:

/*
  * Created on Sep 19, 2003
  *
  * To change the template for this generated file go to
  * Window - Preferences - Java - Code Generation - Code and Comments
  */
package org.ed4becky.mComics;


import org.apache.log4j.PropertyConfigurator;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Log4jInit extends HttpServlet {

   public
   void init() {
   	System.out.println("entering Log4jInit.init()");
     String prefix =  getServletContext().getRealPath("/");
     String file = getInitParameter("log4j-init-file");
     // if the log4j-init-file is not set, then no point in trying
     if(file != null) {
	  System.out.println("processing profile for Log4jInit.init("
	  						+prefix+file+")");
       PropertyConfigurator.configure(prefix+file);
     }
	System.out.println("leaving Log4jInit.init()");
   }

   public
   void doGet(HttpServletRequest req, HttpServletResponse res) {
   }
}


log4j.properties is in the WEB-INF directoru of my app


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
[INVALID FOOTER]