Hello there,

I am using JDK 1.5 & Tomcat 5.5.9 on WinXP...

Set up my init servlet which is supposed to load my log4j.properties
file from myapp/WEB-INF/log4j.properties.

Here's my init servlet's source listing:
------------------------------------------------------------------------------------------------------

package com.acme.logging;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.PropertyConfigurator;

public class Log4jInitServlet extends HttpServlet {
        public void init() throws ServletException  {
       // String prefix = getServletContext().getRealPath("/");
            Properties  p  = new Properties();
            String prefix = "./";
            String file = getInitParameter("log4j-init-file");
            File propFile = new File(prefix+file);
            System.out.println("propFile path is: " + propFile);
            try {
                InputStream is = 
getServletContext().getResourceAsStream("propFile");
        
                if(!propFile.exists()){
                    System.out.println("log4j.properties not found, " +
propFile.getAbsolutePath());
                }
                p.load(is);
                    is.close();
            } catch(IOException e) {
                e.printStackTrace();
            }
       PropertyConfigurator.configureAndWatch(propFile.getAbsolutePath(),10000);
   }
}

Here's my web.xml file:

------------------------------------------------------------------------------------------------------
<!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
   "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>

   <display-name>MySampleApp</display-name>
   <description>
       MySampleApp
   </description>

   <servlet>
     <servlet-name>MySampleAppServlet</servlet-name>
     <servlet-class>com.acme.MySampleAppServlet</servlet-class>
   </servlet>

   <servlet-mapping>
     <servlet-name>MySampleAppServlet</servlet-name>
     <url-pattern>/app</url-pattern>
   </servlet-mapping>

   <servlet>
      <servlet-name>log4j-init</servlet-name>
      <servlet-class>com.acme.logging.Log4jInitServlet</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>      

  <servlet>
      <servlet-name>xml-config-init</servlet-name>
      <servlet-class>com.acme.config.XmlConfigInitServlet</servlet-class>
      <init-param>
          <param-name>xml-config-file</param-name>
          <param-value>WEB-INF\attributes-config.xml</param-value>
      </init-param>
      <load-on-startup>2</load-on-startup>
  </servlet>
</web-app>

------------------------------------------------------------------------------------------------------

Now, when I deploy my app and run Tomcat this is what it says in the Console:

------------------------------------------------------------------------------------------------------
Dec 21, 2006 4:53:14 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Dec 21, 2006 4:53:14 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 847 ms
Dec 21, 2006 4:53:14 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Dec 21, 2006 4:53:14 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/5.5.9
Dec 21, 2006 4:53:14 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Dec 21, 2006 4:53:15 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive affiliates.war
Dec 21, 2006 4:53:16 PM org.apache.catalina.loader.WebappClassLoader
validateJarFile
INFO: 
validateJarFile(C:\DevTools\tomcat\jakarta-tomcat-5.5.9\webapps\affiliates\WEB-INF\lib\servlet-api.jar)
- jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending
class: javax/servlet/Servlet.class
log4j:WARN No appenders could be found for logger
(org.apache.catalina.session.ManagerBase).
log4j:WARN Please initialize the log4j system properly.
propFile path is: .\WEB-INF\log4j.properties
log4j.properties not found,
C:\DevTools\tomcat\jakarta-tomcat-5.5.9\bin\.\WEB-INF\log4j.properties
Dec 21, 2006 4:53:18 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3778 ms

------------------------------------------------------------------------------------------------------

How should I set the prefix in my Log4jInitServlet to point to:

%CATALINA_HOME%/webapps/mywebapp/

Thank you so much!

-JD

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to