org.enhydra.barracuda.core.util.logging
Class Log4jInit

java.lang.Object
  |
  +--javax.servlet.GenericServlet
        |
        +--javax.servlet.http.HttpServlet
              |
              +--org.enhydra.barracuda.core.util.logging.Log4jInit
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

public final class Log4jInit
extends javax.servlet.http.HttpServlet

A servlet for initializing Log4j. See Log4j documentation for how to use Log4j.

This servlet is never called by a client, but should be called during web application initialization, i.e. when the servlet engine starts. The following code should be inserted in the web.xml file for the web application:

 	
 		log4j-init
 	    org.enhydra.barracuda.core.util.logging.Log4jInit
      
           log4j-config
           WEB-INF/log4j.xml
      
      
           log4j-cron
           5000
		
      
           log4j-log-home
           /usr/local/logs/tomcat
		
      1
	
 

The log4j-config init parameter specifies the location of the Log4j configuration file relative to the current webapp. If the log4j-config init parameter is omitted, this class will just let Log4j configure itself since, upon first use of Log4j, if it has not yet been configured, it will search for a config file named log4j.xml or log4j.properties in the classpath. If it can't find one, it falls back to using the BasicConfigurator.configure() to initialize Log4j.

The log4j-cron init parameter specifies the number of milliseconds to wait in between reads of the config file using configureAndWatch(). If omitted, given a value of 0, or given a value that is other than something that which can be converted to a Java long value a normal configure() is used.

The log4j-log-home init parameter is optional. It specifies a custom path to a directory meant to contain log files for the current webapp when using a FileAppender. If not specified, it will default to using the location WEB-INF/logs to contain log files. If the directory doesn't exist, it is created. A system parameter is then created in the following format:

[webapp name].log.home
This can be referenced in an xml config file (not sure if it works for a properties config file?) in the following fashion:
<param name="File" value="${Barracuda.log.home}/main.log" />
In this case, we are running in the "Barracuda" context and the "main.log" file will get created in whatever directory path is specified by the system property "Barracuda.log.home".

Note that if the webapp is being run directly from a .war file, the automatic creation of the WEB-INF/logs directory and [webapp name].log.home system property will *not* be performed. In this case, you would have to provide a custom directory path for the this to work. Also note that configureAndWatch() will not be used in the case that the webapp is running directly from a .war file. configure() will be used instead.

Author:
Jacob Kjome
See Also:
Serialized Form

Constructor Summary
Log4jInit()
           
 
Method Summary
 void doGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Throws a ServletException.
 void doPost(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
           
 java.lang.String getServletInfo()
          Returns the fully qualified class name concatenated with the CVS id.
 void init()
           
 
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service
 
Methods inherited from class javax.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Log4jInit

public Log4jInit()
Method Detail

init

public void init()
          throws javax.servlet.ServletException
Overrides:
init in class javax.servlet.GenericServlet
javax.servlet.ServletException

doGet

public void doGet(javax.servlet.http.HttpServletRequest req,
                  javax.servlet.http.HttpServletResponse res)
           throws javax.servlet.ServletException,
                  java.io.IOException
Throws a ServletException.

Overrides:
doGet in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException

doPost

public void doPost(javax.servlet.http.HttpServletRequest req,
                   javax.servlet.http.HttpServletResponse res)
            throws javax.servlet.ServletException,
                   java.io.IOException
Overrides:
doPost in class javax.servlet.http.HttpServlet
javax.servlet.ServletException
java.io.IOException

getServletInfo

public java.lang.String getServletInfo()
Returns the fully qualified class name concatenated with the CVS id.

Specified by:
getServletInfo in interface javax.servlet.Servlet
Overrides:
getServletInfo in class javax.servlet.GenericServlet


Copyright © 2001 Enhydra.org