Author: mattsicker
Date: Tue May 27 01:06:02 2014
New Revision: 1597689
URL: http://svn.apache.org/r1597689
Log:
Add XSD and fix up HTML.
- Moved anchors into sections.
- Changed title-like bits into <h4> elements.
Modified:
logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/messages.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/migration.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/plugins.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/thread-context.xml
logging/log4j/log4j2/trunk/src/site/xdoc/manual/webapp.xml
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/markers.xml Tue May 27
01:06:02 2014
@@ -16,7 +16,9 @@
limitations under the License.
-->
-<document>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0
http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Log4j 2 API</title>
<author email="[email protected]">Ralph Goers</author>
@@ -24,8 +26,8 @@
<body>
<section name="Log4j 2 API">
- <a name="Markers"/>
<subsection name="Markers">
+ <a name="Markers"/>
<p>
One of the primary purpose of a logging framework is to provide
the means to generate debugging and
diagnostic information only when it is needed, and to allow
filtering of that information so that it
@@ -82,6 +84,7 @@ public class MyApp {
</p>
<p>
Some important rules about Markers must be considered when using
them.
+ </p>
<ol>
<li>Markers must be unique. They are permanently registered by
name so care should be taken
to insure that Markers used in your application are distinct
from those in the application's
@@ -95,7 +98,6 @@ public class MyApp {
times longer than evaluating the Marker itself. Even then
though, evaluating Markers is
inexpensive compared to resolving the callers class name or
line number.</li>
</ol>
- </p>
</subsection>
</section>
</body>
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/messages.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/messages.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/messages.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/messages.xml Tue May 27
01:06:02 2014
@@ -16,7 +16,9 @@
limitations under the License.
-->
-<document>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0
http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Log4j 2 API Messages</title>
<author email="[email protected]">Ralph Goers</author>
@@ -24,8 +26,8 @@
<body>
<section name="Log4j 2 API">
- <a name="Messages"/>
<subsection name="Messages">
+ <a name="Messages"/>
<p>
Although Log4j 2 provides Logger methods that accept Strings and
Objects, all of these are ultimately
captured in Message objects that are then associated with the log
event. Applications are free to
@@ -164,8 +166,8 @@ public class MyApp {
in the SQLMessage instead of having to take place in the business
logic. Finally, if desired, Filters
and/or Layouts can be written to take special action when an
SQLMessage is encountered.
</p>
- <a name="FormattedMessage"/>
<h4>FormattedMessage</h4>
+ <a name="FormattedMessage"/>
<p>
The message pattern passed to a
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/FormattedMessage.html">FormattedMessage</a>
@@ -174,8 +176,8 @@ public class MyApp {
specifiers for String.format(). If so, a StringFormattedMessage is
used to format it. Finally, if the
pattern doesn't match either of those then a ParameterizedMessage is
used to format it.
</p>
- <a name="LocalizedMessage"/>
<h4>LocalizedMessage</h4>
+ <a name="LocalizedMessage"/>
<p>
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/LocalizedMessage.html">LocalizedMessage</a>
is provided primarily to provide compatibility with Log4j 1.x.
Generally,
@@ -187,29 +189,29 @@ public class MyApp {
LocalizedMessage will attempt to locate a bundle with the name of
the Logger used to log the event. The
message retrieved from the bundle will be formatted using a
FormattedMessage.
</p>
- <a name="LoggerNameAwareMessage"/>
<h4>LoggerNameAwareMessage</h4>
+ <a name="LoggerNameAwareMessage"/>
<p>
LoggerNameAwareMessage is an interface with a setLoggerName method.
This method will be called during
event construction so that the Message has the name of the Logger
used to log the event when the
message is being formatted.
</p>
- <a name="MapMessage"/>
<h4>MapMessage</h4>
+ <a name="MapMessage"/>
<p>
A MapMessage contains a Map of String keys and values. MapMessage
implements FormattedMessage and accepts
a format specifier of "XML", in which case the Map will be formatted
as XML. Otherwise, the Map will be
formatted as "key1=value1 key2=value2...".
</p>
- <a name="MessageFormatMessage"/>
<h4>MessageFormatMessage</h4>
+ <a name="MessageFormatMessage"/>
<p>
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/MessageFormatMessage.html">MessageFormatMessage</a>
handles messages that use a <a
href="http://docs.oracle.com/javase/6/docs/api/java/text/MessageFormat.html">conversion
format</a>.
While this Message has more flexibility than ParameterizedMessage,
it is also about two times slower.
</p>
- <a name="MultiformatMessage"/>
<h4>MultiformatMessage</h4>
+ <a name="MultiformatMessage"/>
<p>
A MultiformatMessage will have a getFormats method and a
getFormattedMessage method that accepts and array
of format Strings. The getFormats method may be called by a Layout
to provide it information on what
@@ -218,46 +220,46 @@ public class MyApp {
default format. An example of this is the StructuredDataMessage
which accepts a format String of "XML"
which will cause it to format the event data as XML instead of the
RFC 5424 format.
</p>
- <a name="ObjectMessage"/>
<h4>ObjectMessage</h4>
+ <a name="ObjectMessage"/>
<p>
Formats an Object by calling its toString method.
</p>
- <a name="ParameterizedMessage"/>
<h4>ParameterizedMessage</h4>
+ <a name="ParameterizedMessage"/>
<p>
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/ParameterizedMessage.html">ParameterizedMessage</a>
handles messages that contain "{}" in the format to represent
replaceable tokens and the replacement
parameters.
</p>
- <a name="SimpleMessage"/>
<h4>SimpleMessage</h4>
+ <a name="SimpleMessage"/>
<p>
SimpleMessage contains a String that requires no formatting.
</p>
- <a name="StringFormattedMessage"/>
<h4>StringFormattedMessage</h4>
+ <a name="StringFormattedMessage"/>
<p>
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/StringFormattedMessage.html">StringFormattedMessage</a>
handles messages that use a <a
href="http://docs.oracle.com/javase/6/docs/api/java/util/Formatter.html#syntax">conversion
format</a>
that is compliant with <a
href="http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#format(java.lang.String,
java.lang.Object...)">java.lang.String.format()</a>.
While this Message has more flexibility than ParameterizedMessage,
it is also 5 to 10 times slower.
</p>
- <a name="StructuredDataMessage"/>
<h4>StructuredDataMessage</h4>
+ <a name="StructuredDataMessage"/>
<p>
<a
href="../log4j-api/apidocs/org/apache/logging/log4j/message/StructuredDataMessage.html">StructuredDataMessage</a>
allows applications to add items to a Map as well as set the id to
allow a message to be formatted as a
Structured Data element in accordance with <a
href="http://tools.ietf.org/html/rfc5424">RFC 5424</a>.
</p>
- <a name="ThreadDumpMessage"/>
<h4>ThreadDumpMessage</h4>
+ <a name="ThreadDumpMessage"/>
<p>
A ThreadDumpMessage, if logged, will generate stack traces for all
threads. If running on Java 6+ the
stack traces will include any locks that are held.
</p>
- <a name="TimestampMessage"/>
<h4>TimestampMessage</h4>
+ <a name="TimestampMessage"/>
<p>
A TimestampMessage will provide a getTimestamp method that is called
during event construction. The
timestamp in the Message will be used in lieu of the current
timestamp.
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/migration.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/migration.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/migration.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/migration.xml Tue May 27
01:06:02 2014
@@ -16,7 +16,9 @@
limitations under the License.
-->
-<document>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0
http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Migrating from Log4j 1.x</title>
<author email="[email protected]">Ralph Goers</author>
@@ -24,64 +26,63 @@
<body>
<section name="Migrating from Log4j 1.x">
- <a name="The Log4j 1.x bridge"/>
+ <a name="Log4j1.2Bridge"/>
<subsection name="Using the Log4j 1.x bridge">
<p>
Perhaps the simplest way to convert to using Log4j 2 is to
replace the log4j 1.x jar file with
Log4j 2's <code>log4j-1.2-api.jar</code>. However, to use this
successfully applications must meet the
following requirements:
+ </p>
<ol>
<li>They must not access methods and classes internal to the
Log4j 1.x implementation such
- as <code>Appender</code>s, <code>LoggerRepository</code> or
<code>Category</code>'s
+ as <code>Appender</code>s, <code>LoggerRepository</code> or
<code>Category</code>'s
<code>callAppenders</code> method.</li>
<li>They must not programmatically configure Log4j.</li>
- <li>They must not configure by calling the classes
<code>DOMConfigurator</code> or
+ <li>They must not configure by calling the classes
<code>DOMConfigurator</code> or
<code>PropertyConfigurator</code>.</li>
</ol>
- </p>
</subsection>
<subsection name="Converting to the Log4j 2 API">
<p>For the most part, converting from the Log4j 1.x API to Log4j
2.0 should be fairly simple. Many
of the log statements will require no modification. However,
where necessary the following changes must be
- made.
+ made.</p>
<ol>
<li>
- The main package in version 1 is
<code>org.apache.log4j</code>, in version 2.0 it is
+ The main package in version 1 is
<code>org.apache.log4j</code>, in version 2.0 it is
<code>org.apache.logging.log4j</code>
</li>
<li>
- Calls to <code>org.apache.log4j.Logger.getLogger()</code>
must be modified to
+ Calls to <code>org.apache.log4j.Logger.getLogger()</code>
must be modified to
<code>org.apache.logging.log4j.LogManager.getLogger()</code>.
</li>
<li>
- Calls to
<code>org.apache.log4j.Logger.getRootLogger()</code> or
- <code>org.apache.log4j.LogManager.getRootLogger()</code>
must be replaced with
+ Calls to
<code>org.apache.log4j.Logger.getRootLogger()</code> or
+ <code>org.apache.log4j.LogManager.getRootLogger()</code>
must be replaced with
<code>org.apache.logging.log4j.LogManager.getRootLogger()</code>.</li>
<li>
Calls to <code>org.apache.log4j.Logger.getLogger</code> that
accept a <code>LoggerFactory</code> must
- remove the <code>org.apache.log4j.spi.LoggerFactory</code>
and use one of Log4j 2's other extension
+ remove the <code>org.apache.log4j.spi.LoggerFactory</code>
and use one of Log4j 2's other extension
mechanisms.
</li>
<li>
- Replace calls to
<code>org.apache.log4j.Logger.getEffectiveLevel()</code> with
+ Replace calls to
<code>org.apache.log4j.Logger.getEffectiveLevel()</code> with
<code>org.apache.logging.log4j.Logger.getLevel()</code>.
</li>
<li>
- Remove calls to
<code>org.apache.log4j.LogManager.shutdown()</code>, they are not needed in
version 2
- because the Log4j Core now automatically adds a JVM shutdown
hook on start up to perform any Core
- clean ups.
+ Remove calls to
<code>org.apache.log4j.LogManager.shutdown()</code>, they are not needed in
version 2
+ because the Log4j Core now automatically adds a JVM shutdown
hook on start up to perform any Core
+ clean ups.
</li>
<li>
- Calls to <code>org.apache.log4j.Logger.setLevel()</code> or
similar methods are not supported in the API.
+ Calls to <code>org.apache.log4j.Logger.setLevel()</code> or
similar methods are not supported in the API.
Applications should remove these. Equivalent functionality
is provided in the Log4j 2 implementation
classes but may leave the application susceptible to changes
in Log4j 2 internals.
</li>
<li>
- Where appropriate, applications should convert to use
parameterized messages instead of String
+ Where appropriate, applications should convert to use
parameterized messages instead of String
concatenation.
</li>
</ol>
- </p>
</subsection>
<subsection name="Configuring Log4j 2">
<p>
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/plugins.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/plugins.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/plugins.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/plugins.xml Tue May 27
01:06:02 2014
@@ -26,8 +26,8 @@
<body>
<section name="Plugins">
- <a name="Introduction"/>
<subsection name="Introduction">
+ <a name="Introduction"/>
<p>
Log4j 1.x allowed for extension by requiring class attributes on
most of the configuration
declarations. In the case of some elements, notably the
PatternLayout, the only way to add
@@ -43,8 +43,8 @@
sections.
</p>
</subsection>
- <a name="Core"/>
<subsection name="Core">
+ <a name="Core"/>
<p>
Core plugins are those that are directly represented by an element
in a configuration file, such as an
Appender, Logger or Filter. Custom plugins that conform to the
rules laid out in the next paragraph
@@ -69,8 +69,8 @@
<dd>The current Configuration object will be passed to the
plugin as a parameter.</dd>
</dl>
</subsection>
- <a name="Converters"/>
<subsection name="Converters">
+ <a name="Converters"/>
<p>
Converters are used by
<a
href="../log4j-core/apidocs/org/apache/logging/log4j/core/layout/PatternLayout.html">PatternLayout</a>
@@ -91,8 +91,8 @@
RollingFileAppender to construct the name of the file to log to.
</p>
</subsection>
- <a name="KeyProviders"/>
<subsection name="KeyProviders">
+ <a name="KeyProviders"/>
<p>
Some components within Log4j may provide the ability to perform data
encryption. These components require
a secret key to perform the encryption. Applications may provide the
key by creating a class that
@@ -100,8 +100,8 @@
interface.
</p>
</subsection>
- <a name="Lookups"/>
<subsection name="Lookups">
+ <a name="Lookups"/>
<p>
Lookups are perhaps the simplest plugins of all. They must declare
their type as "Lookup" on the
plugin annotation and must implement the StrLookup interface. They
will have two methods; a
@@ -111,8 +111,8 @@
key is the name of the item to locate.
</p>
</subsection>
- <a name="PluginPreloading"/>
<subsection name="Plugin Preloading">
+ <a name="PluginPreloading"/>
<!-- FIXME: this documentation could probably be simplified quite a
bit thanks to LOG4J2-595 -->
<p>
Scanning for annotated classes dynamically takes a bit of time
during application initialization. Log4j
@@ -146,22 +146,7 @@
<h4>Using the Java annotation processor</h4>
<p>
Annotated classes marked with <code>@Plugin</code> or
<code>@PluginAliases</code> are now automatically
- preloaded when you include the log4j-core artifact, or more
specifically, when you use the following
- dependency:
- </p>
- <!-- FIXME: could this file be renamed to plugins.xml.vm to gain
access to ${Log4jReleaseVersion} -->
- <pre class="prettyprint linenums"><![CDATA[
-<dependencies>
- <dependency>
- <groupId>org.apache.logging.log4j</groupId>
- <artifactId>log4j-plugin-processor</artifactId>
- <version>2.0</version>
- </dependency>
-</dependencies>
- ]]></pre>
- <p>
- Note, however, that explicitly adding this dependency is
unnecessary when you include log4j-core as it is
- used by log4j-core.
+ preloaded when you include the log4j-core artifact.
</p>
</subsection>
</section>
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/thread-context.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/thread-context.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/thread-context.xml
(original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/thread-context.xml Tue May
27 01:06:02 2014
@@ -16,7 +16,9 @@
limitations under the License.
-->
-<document>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0
http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Log4j 2 Thread Context</title>
<author email="[email protected]">Ralph Goers</author>
@@ -116,19 +118,21 @@ ThreadContext.clear();</pre>
<h4>Including the ThreadContext when writing logs</h4>
<p>
The <a
href="../log4j-api/apidocs/org/apache/logging/log4j/core/PatternLayout.html">PatternLayout</a>
- provides mechanisms to print the contents of the
- <a
href="../log4j-api/apidocs/org/apache/logging/log4j/ThreadContext.html">ThreadContext</a>
- Map and Stack.
- <ul>
+ provides mechanisms to print the contents of the
+ <a
href="../log4j-api/apidocs/org/apache/logging/log4j/ThreadContext.html">ThreadContext</a>
+ Map and Stack.
+ </p>
+ <ul>
+ <li>
Use <code>%X</code> by itself to include the full contents of
the Map.
- </ul>
- <ul>
- Use <code>%X{key}</code> to include the specified key.
- </ul>
- <ul>
+ </li>
+ <li>
+ Use <code>%X{key}</code> to include the specified key.
+ </li>
+ <li>
Use <code>%x</code> to include the full contents of the <a
href="http://docs.oracle.com/javase/6/docs/api/java/util/Stack.html">Stack</a>.
- </ul>
- </p>
+ </li>
+ </ul>
</subsection>
</section>
</body>
Modified: logging/log4j/log4j2/trunk/src/site/xdoc/manual/webapp.xml
URL:
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/site/xdoc/manual/webapp.xml?rev=1597689&r1=1597688&r2=1597689&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/site/xdoc/manual/webapp.xml (original)
+++ logging/log4j/log4j2/trunk/src/site/xdoc/manual/webapp.xml Tue May 27
01:06:02 2014
@@ -16,7 +16,9 @@
limitations under the License.
-->
-<document>
+<document xmlns="http://maven.apache.org/XDOC/2.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/XDOC/2.0
http://maven.apache.org/xsd/xdoc-2.0.xsd">
<properties>
<title>Log4j 2 Web Applications</title>
<author email="[email protected]">Nick Williams</author>
@@ -46,16 +48,16 @@
<!-- ... -->
</Configuration>
]]></pre>
- <a name="Servlet-3.0" />
<subsection name="Servlet 3.0 and Newer Web Applications">
+ <a name="Servlet-3.0" />
<p>
A Servlet 3.0 or newer web application is any
<code><web-app></code> whose <code>version</code>
attribute has a value of "3.0" or higher. Of course, the application
must also be running in a compatible
web container. Some examples are: Tomcat 7.0 and higher, GlassFish
3.0 and higher, JBoss 7.0 and higher,
Oracle WebLogic 12c and higher, and IBM WebSphere 8.0 and higher.
</p>
+ <h4>The Short Story</h4>
<p>
- <b>The Short Story</b><br />
Log4j 2 "just works" in Servlet 3.0 and newer web applications. It
is capable of automatically starting when
the application deploys and shutting down when the application
undeploys.
</p>
@@ -67,8 +69,8 @@
will need to change <code>catalina.properties</code> and remove
"log4j*.jar" from the <code>jarsToSkip</code>
property. You may need to do something similar on other containers
if they skip scanning Log4j JAR files.
</p>
+ <h4>The Long Story</h4>
<p>
- <b>The Long Story</b><br />
The Log4j 2 Core JAR file is a web-fragment configured to order
before any other web fragments in your
application. It contains a <code>ServletContainerInitializer</code>
(<a
href="../log4j-core/apidocs/org/apache/logging/log4j/web/Log4jServletContainerInitializer.html"
@@ -85,11 +87,11 @@
deployment descriptor with the value "true" to disable
auto-initialization. You <em>must</em> define the
context parameter in <code>web.xml</code>. If you set in
programmatically, it will be too late for Log4j
to detect the setting.
+ </p>
<pre class="prettyprint linenums"><![CDATA[ <context-param>
<param-name>isLog4jAutoInitializationDisabled</param-name>
<param-value>true</param-value>
</context-param>]]></pre>
- </p>
<p>
Once you disable auto-initialization, you must initialize Log4j as
you would a
<a href="#Servlet-2.5">Servlet 2.5 web application</a>. You must do
so in a way that this initialization
@@ -106,8 +108,8 @@
erroneous behavior.
</p>
</subsection>
- <a name="Servlet-2.5" />
<subsection name="Servlet 2.5 Web Applications">
+ <a name="Servlet-2.5" />
<p>
A Servlet 2.5 web application is any <code><web-app></code>
whose <code>version</code> attribute has a
value of "2.5." The <code>version</code> attribute is the only thing
that matters; even if the web application
@@ -125,6 +127,7 @@
requests of any type. The listener should be the very first listener
defined in your application, and the
filter should be the very first filter defined and mapped in your
application. This is easily accomplished
using the following <code>web.xml</code> code:
+ </p>
<pre class="prettyprint linenums"><![CDATA[ <listener>
<listener-class>org.apache.logging.log4j.core.web.Log4jServletContextListener</listener-class>
</listener>
@@ -142,15 +145,14 @@
<dispatcher>ERROR</dispatcher>
<dispatcher>ASYNC</dispatcher><!-- Servlet 3.0 w/ disabled
auto-initialization only; not supported in 2.5 -->
</filter-mapping>]]></pre>
- </p>
<p>
You can customize the behavior of the listener and filter using the
<code>log4jContextName</code>,
<code>log4jConfiguration</code>, and/or
<code>isLog4jContextSelectorNamed</code> context parameters. Read more
about this in the <a href="#ContextParams">Context Parameters</a>
section below.
</p>
</subsection>
- <a name="ContextParams" />
<subsection name="Context Parameters">
+ <a name="ContextParams" />
<p>
By default, Log4j 2 uses the <code>ServletContext</code>'s context
name as the <code>LoggerContext</code> name
and uses the standard pattern for locating the Log4j configuration
file. There are three context parameters
@@ -178,23 +180,18 @@
<code>ServletContext</code> within a listener, Log4j will initialize
before the context parameters are
available and they will have no effect. Here are some sample uses of
these context parameters.
</p>
- <p>
- <b>Set the Logging Context Name to "myApplication"</b>
- <pre class="prettyprint linenums"><![CDATA[ <context-param>
+ <h4>Set the Logging Context Name to "myApplication"</h4>
+ <pre class="prettyprint linenums"><![CDATA[ <context-param>
<param-name>log4jContextName</param-name>
<param-value>myApplication</param-value>
</context-param>]]></pre>
- </p>
- <p>
- <b>Set the Configuration Path/File/URI to
"/etc/myApp/myLogging.xml"</b>
- <pre class="prettyprint linenums"><![CDATA[ <context-param>
+ <h4>Set the Configuration Path/File/URI to
"/etc/myApp/myLogging.xml"</h4>
+ <pre class="prettyprint linenums"><![CDATA[ <context-param>
<param-name>log4jConfiguration</param-name>
<param-value>file:///etc/myApp/myLogging.xml</param-value>
</context-param>]]></pre>
- </p>
- <p>
- <b>Use the <code>JNDIContextSelector</code></b>
- <pre class="prettyprint linenums"><![CDATA[ <context-param>
+ <h4>Use the <code>JNDIContextSelector</code></h4>
+ <pre class="prettyprint linenums"><![CDATA[ <context-param>
<param-name>isLog4jContextSelectorNamed</param-name>
<param-value>true</param-value>
</context-param>
@@ -206,20 +203,21 @@
<param-name>log4jConfiguration</param-name>
<param-value>file:///D:/conf/myLogging.xml</param-value>
</context-param>]]></pre>
+ <p>
Note that in this case you must also set the "Log4jContextSelector"
system property to
"org.apache.logging.log4j.core.selector.JNDIContextSelector."
</p>
</subsection>
- <a name="WebLookup" />
<subsection name="Using Web Application Information During the
Configuration">
+ <a name="WebLookup" />
<p>
You may want to use information about the web application during
configuration. For example, you could embed
the web application's context path in the name of a Rolling File
Appender. See WebLookup in
<a href="./lookups.html#WebLookup">Lookups</a> for more information.
</p>
</subsection>
- <a name="JspLogging" />
<subsection name="JavaServer Pages Logging">
+ <a name="JspLogging" />
<p>
You may use Log4j 2 within JSPs just as you would within any other
Java code. Simple obtain a
<code>Logger</code> and call its methods to log events. However,
this requires you to use Java code within
@@ -241,8 +239,8 @@
property. You may need to do something similar on other containers
if they skip scanning Log4j JAR files.
</p>
</subsection>
- <a name="Async" />
<subsection name="Asynchronous Requests and Threads">
+ <a name="Async" />
<p>
The handling of asynchronous requests is tricky, and regardless of
Servlet container version or configuration
Log4j cannot handle everything automatically. When standard
requests, forwards, includes, and error resources
@@ -281,7 +279,8 @@
its <code>clearLoggerContext</code> method as the very last line of
code in your asynchronous thread. The
following code demonstrates this. It uses the container thread pool
to execute asynchronous request
processing, passing an anonymous inner <code>Runnable</code> to the
<code>start</code> method.
- <pre class="prettyprint linenums"><![CDATA[public class AsyncServlet
extends HttpServlet
+ </p>
+ <pre class="prettyprint linenums"><![CDATA[public class AsyncServlet
extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
@@ -305,7 +304,6 @@
});
}
}]]></pre>
- </p>
<p>
Note that you <em>must</em> call <code>clearLoggerContext</code>
once your thread is finished
processing. Failing to do so will result in memory leaks. If using a
thread pool, it can even disrupt the
@@ -313,7 +311,8 @@
context in a <code>finally</code> block, which will always execute.
As a shortcut, you can use the
<code>wrapExecution</code> method, which takes care of setting the
context, executing the code you pass in,
and clearing the context in a finally black. This is especially
convenient when using Java 8 lambdas.
- <pre class="prettyprint linenums"><![CDATA[public class AsyncServlet
extends HttpServlet
+ </p>
+ <pre class="prettyprint linenums"><![CDATA[public class AsyncServlet
extends HttpServlet
{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response)
@@ -330,7 +329,6 @@
});
}
}]]></pre>
- </p>
</subsection>
</section>
</body>