1 /* *************************************************************************** 2 * Copyright (c) 2012 Brabenetz Harald, Austria. 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 18 package org.settings4j.helper.web; 19 20 import javax.servlet.ServletContextEvent; 21 import javax.servlet.ServletContextListener; 22 23 import org.apache.log4j.LogManager; 24 25 26 /** 27 * {@link javax.servlet.ServletContextListener} to initialize the {@link Log4jConfigurationLoader}. 28 * <p> 29 * Example Configuration could look like the following: 30 * 31 * <pre> 32 * web.xml 33 * -------------------------------------- 34 * 35 * <context-param> 36 * <param-name>settings4jLog4jConfigurationKey</param-name> 37 * <param-value>com/myCompany/myApp/log4j.configuration</param-value> 38 * </context-param> 39 * 40 * <listener> 41 * <display-name></display-name> 42 * <listener-class>org.settings4j.helper.web.Log4jConfigurationLoaderListener</listener-class> 43 * </listener> 44 * -------------------------------------- 45 * </pre> 46 * You can combine this config with he {@link DefaultPropertiesLoaderListener}. 47 * 48 * @author brabenetz 49 */ 50 public class Log4jConfigurationLoaderListener implements ServletContextListener { 51 52 /** {@inheritDoc} */ 53 public void contextInitialized(final ServletContextEvent event) { 54 new Log4jConfigurationLoader().initLog4jConfiguration(event.getServletContext()); 55 } 56 57 58 /** {@inheritDoc} */ 59 public void contextDestroyed(final ServletContextEvent event) { 60 LogManager.shutdown(); 61 } 62 63 }