01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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;
20: import javax.servlet.ServletContextListener;
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: * @author Juergen Hoeller
37: * @since 13.03.2003
38: * @see Log4jWebConfigurer
39: * @see Log4jConfigServlet
40: * @see org.springframework.web.context.ContextLoaderListener
41: * @see org.springframework.web.context.ContextLoaderServlet
42: * @see WebAppRootListener
43: */
44: public class Log4jConfigListener implements ServletContextListener {
45:
46: public void contextInitialized(ServletContextEvent event) {
47: Log4jWebConfigurer.initLogging(event.getServletContext());
48: }
49:
50: public void contextDestroyed(ServletContextEvent event) {
51: Log4jWebConfigurer.shutdownLogging(event.getServletContext());
52: }
53:
54: }
|