1 /*** 2 * The contents of this file are subject to the Mozilla Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/MPL/ 6 * 7 * Software distributed under the License is distributed on an "AS 8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 9 * implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is pow2toolkit library. 13 * 14 * The Initial Owner of the Original Code is 15 * Power Of Two S.R.L. (www.pow2.com) 16 * 17 * Portions created by Power Of Two S.R.L. are 18 * Copyright (C) Power Of Two S.R.L. 19 * All Rights Reserved. 20 * 21 * Contributor(s): 22 */ 23 24 package com.pow2.resources; 25 26 27 import javax.servlet.ServletException; 28 29 import org.apache.log4j.PropertyConfigurator; 30 31 import com.pow2.util.Util; 32 33 34 /*** 35 * Log4J init servlet. 36 * <br> 37 * Configure and initialize Log4j defining the following servlet 38 * into the web.xml file of your web-application. 39 * 40 * <code> 41 * <pre> 42 * <servlet> 43 * <servlet-name>log4j-init</servlet-name> 44 * <servlet-class>com.pow2.resources.Log4jInit</servlet-class> 45 * 46 * <init-param> 47 * <param-name>log4j-init-file</param-name> 48 * <param-value>WEB-INF/log4j.properties</param-value> 49 * </init-param> 50 * 51 * <load-on-startup>1</load-on-startup> 52 * </servlet> 53 * </pre> 54 * </code> 55 * 56 * See 57 * <ul> 58 * <li><a href="http://jakarta.apache.org/log4j/docs/index.html">http://jakarta.apache.org/log4j/docs/index.html</a></li> 59 * <li><a href="http://jakarta.apache.org/log4j/docs/manual.html">http://jakarta.apache.org/log4j/docs/manual.html</a></li> 60 * </ul> 61 * for further details. 62 */ 63 public class Log4jInit extends InitServlet 64 { 65 /*** 66 * Configure Log4J using the configuration file whose path is set 67 * by the <code>log4j-init-file</code> parameter 68 * of the <code>web.xml</code> file. 69 */ 70 public void init() throws ServletException 71 { 72 super.init(); 73 String file = getInitParameterFilePath("log4j-init-file"); 74 75 if (Util.isNull(file)) 76 { 77 String err = "cannot configure log4j logging package. Log4J config file is null"; 78 throw new ServletException(err); 79 } 80 81 PropertyConfigurator.configure(file); 82 cat.info("::init - log4j successfully configured."); 83 } 84 }