Yep, however ...

I want to have my webserver to launch a servlet that initializes the logging
package once.
Here, we have a 'virtual path v.s. real path' problem.

I resolved it today by writing the following servlet. The servlet needs to
be configured in the web server deployment descriptor (typically web.xml).

The following two code snippets illustrate the solution.

        - Fernand.


snippet 1: web.xml configuration
-------------------------------

  <servlet>  
    <servlet-name>logger</servlet-name>
    <servlet-class>com.compuware.log4j.Log4jServlet</servlet-class>
    <init-param>
      <param-name>log4jConfigFile</param-name>
      <param-value>/WEB-INF/classes/log4j.xml</param-value>
    </init-param>
    <load-on-startup>4</load-on-startup>
  </servlet>


snippet 2: The servlet: com.compuware.log4j.Log4jServlet.java
-------------------------------------------------------------

package com.compuware.Package.log4j;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.UnavailableException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import javax.servlet.GenericServlet;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.log4j.Category;
import org.apache.log4j.Priority;
import org.apache.log4j.xml.DOMConfigurator;
import com.compuware.log4j.APCategory;
import com.compuware.log4j.APPriority;

public class Log4jServlet extends GenericServlet {

  public static APCategory logger;

  public void init() {
    String s1, s2, s3;
    String configFile;
    
    
    s1 = getServletConfig().getInitParameter("log4jConfigFile");
    s2 = getServletContext().getRealPath(s1);
    s3 = "file:///" + s2;
    System.setProperty("log4j.configuration", s3);
    DOMConfigurator.configureAndWatch("log4j.xml");
    
  }

  public void service(ServletRequest req, ServletResponse res)
         throws ServletException, java.io.IOException {
  }
}





-----Original Message-----
From: Jim Moore [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 01, 2001 3:44 PM
To: 'LOG4J Users Mailing List'
Subject: RE: Difference in using BasicConfigurator v.s. DOMCOnfigurator


You have to provide what file to use as a system property. For example:

java -Dlog4j.configuration=file:log4j.xml MyProgram

-Jim Moore


-----Original Message-----
From: Rouwendaal, Fernand [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 01, 2001 3:17 AM
To: '[EMAIL PROTECTED]'
Subject: Difference in using BasicConfigurator v.s. DOMCOnfigurator


Hi,

When using the BasicConfigurator, you can make use of a very handy feature:
The configuration file log4j.properties is searched for in the classpath.
Benefit: In your code, you never have to specify the location hardcoded.

When using the DOMConfigurator, I cannot make this mechanism to work. Am I
doing something wrong, or is this feature unsupported for DOMConfigurators ?

        - Fernand.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to