Log4j Web
Contains classes that can be used to initialize logging within a web application.
Log4jContextListener
Log4j provides a ServletContextListener that will initialize the LoggerContext for your web
application. It accepts two initialization parameters:
- log4jContextName - the name to be given to the LoggerContext. If not specified this will
default to the display-name of the web application.
- log4jConfiguration - the location of the Log4j configuration file. If the file protocol
is not specified then the file will be located both in the class path and on the file system.
If the location is a relative path the file location will be relative to the current
working directory of the running server.
To register this listener, make sure that the log4j-web-2.0.jar file is
in the classpath (either in your web application's WEB-INF/lib directory
or in the container's classpath) and add the following snippet to your web.xml:
<listener>
<listener-class>org.apache.logging.log4j.core.web.Log4jContextListener</listener-class>
</listener>
Either or both of the initialization parameters may contain variables of the form ${sys:propertyName} or
${env:propertyName} to allow substitution using either a system property or an environment variable.
JNDIContextFilter
The JNDIContextFilter is a Servlet Filter that can be used in conjunction with the JNDIContextSelector
to identify the LoggerContext that should be used. It accepts two parameters.
- context-name - the name to be given to the LoggerContext. A context name must be specified.
- config-location - the location of the Log4j configuration file.
Requirements
The Log4j web components require at least Java 6 and at least Servlet 2.5 (or Java EE 5).
|