KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > util > Log4jConfigListener


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.util;
18
19 import javax.servlet.ServletContextEvent JavaDoc;
20 import javax.servlet.ServletContextListener JavaDoc;
21
22 /**
23  * Bootstrap listener for custom Log4J initialization in a web environment.
24  * Delegates to Log4jWebConfigurer (see its javadoc for configuration details).
25  *
26  * <b>WARNING: Assumes an expanded WAR file</b>, both for loading the configuration
27  * file and for writing the log files. If you want to keep your WAR unexpanded or
28  * don't need application-specific log files within the WAR directory, don't use
29  * Log4J setup within the application (thus, don't use Log4jConfigListener or
30  * Log4jConfigServlet). Instead, use a global, VM-wide Log4J setup (for example,
31  * in JBoss) or JDK 1.4's <code>java.util.logging</code> (which is global too).
32  *
33  * <p>This listener should be registered before ContextLoaderListener in web.xml,
34  * when using custom Log4J initialization.
35  *
36  * <p>For Servlet 2.2 containers and Servlet 2.3 ones that do not
37  * initalize listeners before servlets, use Log4jConfigServlet.
38  * See the ContextLoaderServlet javadoc for details.
39  *
40  * @author Juergen Hoeller
41  * @since 13.03.2003
42  * @see Log4jWebConfigurer
43  * @see Log4jConfigServlet
44  * @see org.springframework.web.context.ContextLoaderListener
45  * @see org.springframework.web.context.ContextLoaderServlet
46  * @see WebAppRootListener
47  */

48 public class Log4jConfigListener implements ServletContextListener JavaDoc {
49
50     public void contextInitialized(ServletContextEvent JavaDoc event) {
51         Log4jWebConfigurer.initLogging(event.getServletContext());
52     }
53
54     public void contextDestroyed(ServletContextEvent JavaDoc event) {
55         Log4jWebConfigurer.shutdownLogging(event.getServletContext());
56     }
57
58 }
59
Popular Tags