View Javadoc
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   * &lt;context-param&gt;
36   *     &lt;param-name&gt;settings4jLog4jConfigurationKey&lt;/param-name&gt;
37   *     &lt;param-value&gt;com/myCompany/myApp/log4j.configuration&lt;/param-value&gt;
38   * &lt;/context-param&gt;
39   * 
40   * &lt;listener&gt;
41   *     &lt;display-name&gt;&lt;/display-name&gt;
42   *     &lt;listener-class&gt;org.settings4j.helper.web.Log4jConfigurationLoaderListener&lt;/listener-class&gt;
43   * &lt;/listener&gt;
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  }