Luc,

The listener element is only valid in the Servlet 2.3 web.xml file, if
using a previous servlet version use the attached servlet set to load at
startup before any of the other servlets.

The jar containing my classes should be included in your WEB-INF/lib
directory in each web application.

Paul

On Fri, 2005-09-02 at 09:07 -0400, [EMAIL PROTECTED] wrote:
> I'm having the same issue and after trying to follow the instructions given 
> by Paul Austin, I've got stuck on the part that says to add a listener. 
> 
> There's no place for a listener in web.xml according to the dtd validation 
> file. Am I wrong ? (I'm using Tomcat 5.5.9 with the struts framework)
> 
> Everything else went fine. I've created a jar file with your source code. 
> BTW, where am I supposed to put this jar anyways ? in common/lib/ ??
> 
> And just to double check, is this log4j.xml file valid ? :
> 
> -------------------------------------------
> 
> <?xml version="1.0" encoding="UTF-8" ?>
> <!-- <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> -->
> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/";>
>   <appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
>     <layout class="org.apache.log4j.SimpleLayout"/>
>   </appender>
>   <root>
>     <priority value ="debug" />
>     <appender-ref ref="ConsoleAppender"/>
>   </root>
> </log4j:configuration>
> 
> -------------------------------------------
> 
> Thanks a lot 
> 
> ____________________________
> Luc Boudreau
> SID - Université du Québec
> [EMAIL PROTECTED]
>  
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
/*
 * Copyright 2005 Revolution Systems Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.revolsys.logging.log4j;

import java.io.InputStream;

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

import org.apache.log4j.Hierarchy;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * The Log4jInitializationServlet class uses the
 * [EMAIL PROTECTED] ContextClassLoaderRepositorySelector} to maintain a separate Log4j
 * configuration for a servlet context and to load the logging configuration
 * from the log4j.xml file specified by the log4jXmlLocation context-param (or
 * /WEB-INF/log4j.xml if not specified).
 * 
 * @author Paul Austin
 * @version 1.0
 */
public class Log4jInitializationServlet extends HttpServlet {
    /** The default location for the log4j.xml file. */
    public static final String DEFAULT_LOG4J_XML_LOCATION = "/WEB-INF/log4j.xml";

    /**
     * Initialize the logging for context by creating a new heirarchy for the
     * current thread context class context and loading the configuration from
     * the log4jXmlLocation context-param.
     * 
     * @param config The servlet configuration.
     * @throws ServletException If there was a problem initializing the servlet.
     */
    public void init(final ServletConfig config) throws ServletException {
        super.init(config);
        Hierarchy hierarchy = ContextClassLoaderRepositorySelector.add();
        ServletContext context = config.getServletContext();
        String log4jXml = context.getInitParameter("log4jXmlLocation");
        if (log4jXml == null) {
            log4jXml = DEFAULT_LOG4J_XML_LOCATION;
        }
        try {
            InputStream log4JConfig = context.getResourceAsStream(log4jXml);
            if (log4JConfig != null) {
                DOMConfigurator conf = new DOMConfigurator();
                conf.doConfigure(log4JConfig, hierarchy);
            }
        } catch (Exception e) {
            throw new ServletException(e);
        }
    }

    /**
     * Clean up the servlet by removing the logging configuration for the
     * current context.
     */
    public void destroy() {
        ContextClassLoaderRepositorySelector.remove();
    }

}

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

Reply via email to