blob: 7233bac33be4911e7077875ed52d857fcb21bc83 [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
| Generated by Apache Maven Doxia at Jun 9, 2012
| Rendered using Apache Maven Fluido Skin
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>
Log4j 2 Layouts</title>
<link rel="stylesheet" href="../css/apache-maven-fluido.min.css" />
<link rel="stylesheet" href="../css/site.css" />
<link rel="stylesheet" href="../css/print.css" media="print" />
<script type="text/javascript" src="../js/apache-maven-fluido.min.js"></script>
<meta name="author" content="Ralph Goers" />
<meta name="Date-Revision-yyyymmdd" content="20120609" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<div id="banner">
<div class="pull-left">
<a href="../../../" id="bannerLeft">
<img src="../images/ls-logo.jpg" alt="Apache Logging Services™"/>
</a>
</div>
<div class="pull-right"> <div id="bannerRight">
<img src="../images/logo.jpg" />
</div>
</div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 2012-06-09</li>
<li class="divider">|</li> <li id="projectVersion">Version: 2.0-alpha1-SNAPSHOT</li>
<li class="pull-right"> <a href="http://wiki.apache.org/logging" class="externalLink" title="Logging Wiki">Logging Wiki</a>
</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="http://www.apache.org/" class="externalLink" title="Apache">Apache</a>
</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="../../../" title="Logging Services">Logging Services</a>
</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="../../" title="Log4j">Log4j</a>
</li>
<li class="divider pull-right">|</li>
<li class="pull-right"> <a href="../../companions" title="Log4j Companions">Log4j Companions</a>
</li>
</ul>
</div>
<div class="row-fluid">
<div id="leftColumn" class="span3">
<div class="well sidebar-nav">
<h3>Apache Log4j™ 2</h3>
<ul>
<li class="none">
<a href="../index.html" title="About">About</a>
</li>
<li class="none">
<a href="../download.html" title="Download">Download</a>
</li>
<li class="none">
<a href="../build.html" title="Build and Install">Build and Install</a>
</li>
<li class="none">
<a href="../changelog.html" title="Changelog">Changelog</a>
</li>
</ul>
<h3>Manual</h3>
<ul>
<li class="none">
<a href="../manual/index.html" title="Introduction">Introduction</a>
</li>
<li class="none">
<a href="../manual/architecture.html" title="Architecture">Architecture</a>
</li>
<li class="collapsed">
<a href="../manual/api.html" title="API">API</a>
</li>
<li class="collapsed">
<a href="../manual/configuration.html" title="Configuration">Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/plugins.html" title="Plugins">Plugins</a>
</li>
<li class="collapsed">
<a href="../manual/lookups.html" title="Lookups">Lookups</a>
</li>
<li class="collapsed">
<a href="../manual/appenders.html" title="Appenders">Appenders</a>
</li>
<li class="expanded">
<strong>Layouts</strong>
<ul>
<li class="none">
<a href="../manual/layouts.html#HTMLLayout" title="HTML">HTML</a>
</li>
<li class="none">
<a href="../manual/layouts.html#PatternLayout" title="Pattern">Pattern</a>
</li>
<li class="none">
<a href="../manual/layouts.html#RFC5424Layout" title="RFC5424">RFC5424</a>
</li>
<li class="none">
<a href="../manual/layouts.html#SerializedLayout" title="Serialized">Serialized</a>
</li>
<li class="none">
<a href="../manual/layouts.html#SyslogLayout" title="Syslog">Syslog</a>
</li>
<li class="none">
<a href="../manual/layouts.html#XMLLayout" title="XML">XML</a>
</li>
</ul>
</li>
<li class="collapsed">
<a href="../manual/filters.html" title="Filters">Filters</a>
</li>
<li class="none">
<a href="../manual/jmx.html" title="JMX">JMX</a>
</li>
<li class="none">
<a href="../manual/logsep.html" title="Logging Separation">Logging Separation</a>
</li>
<li class="collapsed">
<a href="../manual/extending.html" title="Extending Log4j">Extending Log4j</a>
</li>
</ul>
<h3>Logging Adapters</h3>
<ul>
<li class="none">
<a href="../log4j12-api/api.html" title="Log4j 1.x API">Log4j 1.x API</a>
</li>
<li class="none">
<a href="../log4j2-jcl/api.html" title="Commons Logging">Commons Logging</a>
</li>
<li class="none">
<a href="../slf4j-impl/api.html" title="SLF4J">SLF4J</a>
</li>
</ul>
<h3>Components</h3>
<ul>
<li class="none">
<a href="../log4j-api/index.html" title="API">API</a>
</li>
<li class="none">
<a href="../log4j-core/index.html" title="Impl">Impl</a>
</li>
<li class="none">
<a href="../log4j12-api/index.html" title="Log4J 1.2 API">Log4J 1.2 API</a>
</li>
<li class="none">
<a href="../log4j-jcl/index.html" title="Commons Logging Bridge">Commons Logging Bridge</a>
</li>
<li class="none">
<a href="../slf4j-impl/index.html" title="SLF4J Binding">SLF4J Binding</a>
</li>
<li class="none">
<a href="../log4j-flume-og/index.html" title="Flume OG">Flume OG</a>
</li>
<li class="none">
<a href="../log4j-flume-ng/index.html" title="Flume NG">Flume NG</a>
</li>
</ul>
<h3>Project Documentation</h3>
<ul>
<li class="collapsed">
<a href="../project-info.html" title="Project Information">Project Information</a>
</li>
<li class="collapsed">
<a href="../project-reports.html" title="Project Reports">Project Reports</a>
</li>
</ul>
<hr class="divider" />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="../images/logos/maven-feather.png" />
</a>
</div>
</div>
</div>
<div id="bodyColumn" class="span9" >
<!-- Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. -->
<div class="section"><h2>Layouts<a name="Layouts"></a></h2>
<p>
Layouts are used by Appenders to format the LogEvent into a form that meets the needs of whoever will be
consuming the log events. In Log4j 1.x and Logback Layouts were expected to transform an event into a
String. In Log4j 2 Layouts return a byte array. This allows the result of the Layout to be useful in
many more types of Appenders. However, this means most Layouts need to be configured with a
<a class="externalLink" href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a> to
insure the byte array contains correct values.
</p>
<a name="HTMLLayout"></a>
<div class="section"><h3>HTMLLayout<a name="HTMLLayout"></a></h3>
<p>
The HTMLLayout generates an HTML page and adds each LogEvent to a row in a table.
</p>
<table class="zebra-striped" border="1" width="100%"><caption align="top">HTML Layout Parameters</caption>
<tr class="a">
<th>Parameter Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr class="b">
<td>charset</td>
<td>String</td>
<td>The character set to use when converting the HTML String to a byte array. The value must be
a valid <a class="externalLink" href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a>.
If not specified, the default system Charset will be used.</td>
</tr>
<tr class="a">
<td>contentType</td>
<td>String</td>
<td>The value to assign to the Content-Type header. The default is &quot;text/html&quot;.</td>
</tr>
<tr class="b">
<td>locationInfo</td>
<td>boolean</td>
<td>If true, the filename and line number will be included in the HTML output. The default value is
false.</td>
</tr>
<tr class="a">
<td>title</td>
<td>String</td>
<td>A String that will appear as the HTML title.</td>
</tr>
</table>
</div>
<a name="PatternLayout"></a>
<div class="section"><h3>PatternLayout<a name="PatternLayout"></a></h3>
<p>
A flexible layout configurable with pattern string. The goal of this class is to format a LogEvent and
return the results. The format of the result depends on the <i>conversion pattern</i>.
</p>
<p>
The conversion pattern is closely related to the conversion pattern of the printf function in C.
A conversion pattern is composed of literal text and format control expressions called
<i>conversion specifiers</i>.
</p>
<p>
<i>Note that any literal text may be included in the conversion pattern.</i>
</p>
<p>
Each conversion specifier starts with a percent sign (%) and is followed by optional <i>format
modifiers</i> and a <i>conversion character</i>. The conversion character specifies the type of
data, e.g. category, priority, date, thread name. The format modifiers control such things as field width,
padding, left and right justification. The following is a simple example.
</p>
<p>
Let the conversion pattern be <b>&quot;%-5p [%t]: %m%n&quot;</b> and assume that the log4j environment was set to
use a PatternLayout. Then the statements
</p><div><pre>
Logger logger = LogManager.getLogger(&quot;MyLogger&quot;);
logger.debug(&quot;Message 1&quot;);
logger.warn(&quot;Message 2&quot;);
</pre></div>
would yield the output
<div><pre>
DEBUG [main]: Message 1
WARN [main]: Message 2
</pre></div>
<p>
Note that there is no explicit separator between text and conversion specifiers. The pattern parser
knows when it has reached the end of a conversion specifier when it reads a conversion character.
In the example above the conversion specifier <b>%-5p</b> means the priority of the logging event should
be left justified to a width of five characters.
</p>
<table class="zebra-striped" border="1" width="100%"><caption align="top">Pattern Layout Parameters</caption>
<tr class="a">
<th>Parameter Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr class="b">
<td>charset</td>
<td>String</td>
<td>The character set to use when converting the syslog String to a byte array. The String must be
a valid<a class="externalLink" href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a>.
If not specified, the default system Charset will be used.
</td>
</tr>
<tr class="a">
<td>pattern</td>
<td>String</td>
<td></td>
</tr>
<tr class="b">
<td>replace</td>
<td>RegexReplacement</td>
<td>Allows portions of the resulting String to be replaced. If configured, the replace element must
specify the regular expression to match and the substitution. This performs a function similar to
the RegexReplacement converter but applies to the whole message while the converter only
applies to the String its pattern generates.
</td>
</tr>
</table>
<div class="section"><h4>Patterns<a name="Patterns"></a></h4>
<p>
The conversions that are provided with Log4j are:
</p>
<table class="zebra-striped" border="1" width="100%">
<tr class="a">
<th>Conversion Pattern</th>
<th>Description</th>
</tr>
<tr class="b">
<td align="center">
<b>c</b>{precision}<br />
<b>logger</b>{precision}
</td>
<td>
<p>
Used to output the name of the logger that published the logging event. The logger conversion
specifier can be optionally followed by<i>precision specifier</i>, which consists of a
decimal integer, or a pattern starting with a decimal integer.
</p>
<p>If a precision specifier is given and it is an integer value, then only the corresponding number
of right most components of the logger name will be printed. If the precision contains
other non-integer characters then the name will be abbreviated based on the pattern. If the
precision integer is less than one the right-most token will still be printed in full.
By default the logger name is printed in full.
</p>
<table class="zebra-striped" border="1" width="100%">
<tr class="a">
<th>Conversion Pattern</th>
<th>Logger Name</th>
<th>Result</th>
</tr>
<tr class="b">
<td>%c{1}</td>
<td>org.apache.commons.Foo</td>
<td>Foo</td>
</tr>
<tr class="a">
<td>%c{2}</td>
<td>org.apache.commons.Foo</td>
<td>commons.Foo</td>
</tr>
<tr class="b">
<td>%c{1.}</td>
<td>org.apache.commons.Foo</td>
<td>o.a.c.Foo</td>
</tr>
<tr class="a">
<td>%c{1.1.~.~}</td>
<td>org.apache.commons.test.Foo</td>
<td>o.a.~.~.Foo</td>
</tr>
<tr class="b">
<td>%c{.}</td>
<td>org.apache.commons.test.Foo</td>
<td>....Foo</td>
</tr>
</table>
</td>
</tr>
<tr class="a">
<td align="center">
<b>C</b>{precision}<br />
<b>class</b>{precision}
</td>
<td>
<p>
Used to output the fully qualified class name of the caller issuing the logging request.
This conversion specifier can be optionally followed by<i>precision specifier</i>, that
follows the same rules as the logger name converter.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>d</b>{pattern}<br />
<b>date</b>{pattern}
</td>
<td>
<p>
Used to output the date of the logging event. The date conversion specifier may be
followed by a set of braces containing a date and time pattern strings
<a class="externalLink" href="http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html">
SimpleDateFormat</a>,
<i>ABSOLUTE</i>,
<i>DATE</i>
or
<i>ISO8601</i>
and a set of braces containing a time zone id per
<a class="externalLink" href="http://docs.oracle.com/javase/6/docs/api/java/util/TimeZone.html#getTimeZone(java.lang.String)">
java.util.TimeZone.getTimeZone</a>.
For example,<b>%d{HH:mm:ss,SSS}</b>,<b>%d{dd&#160;MMM&#160;yyyy&#160;HH:mm:ss,SSS}</b>,
<b>%d{DATE}</b>
or<b>%d{HH:mm:ss}{GMT+0}</b>. If no date format specifier is given then
ISO8601 format is assumed.
</p>
</td>
</tr>
<tr class="a">
<td align="center">
<b>ex</b>{depth}<br />
<b>exception</b>{depth}<br />
<b>throwable</b>{depth}
</td>
<td>
<p>Used to output the Throwable trace that has been bound to the LoggingEvent, by
default this will output the full trace as one would normally find by a call to
Throwable.printStackTrace().
The throwable conversion word can be followed by an option in the form
<b>%throwable{short}</b>
which will only output the first line of the Throwable or <b>%throwable{n}</b> where
the first n lines of the stacktrace will be printed.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>F</b><br />
<b>file</b>
</td>
<td>
Used to output the file name where the logging request was issued.
</td>
</tr>
<tr class="a">
<td align="center">
<b>K</b>{key}<br />
<b>map</b>{key}<br />
<b>MAP</b>{key}
</td>
<td>
<p>Used to output the entries in a <a href="../log4j2-api/apidocs/index.html">MapMessage</a>,
if one is present in the event. The <b>K</b> conversion character can be followed by the key
for the map placed between braces, as in
<b>%K{clientNumber}</b> where <tt>clientNumber</tt> is the key. The value in the Map
corresponding to the key will be output. If no additional sub-option
is specified, then the entire contents of the Map key value pair set
is output using a format {{key1,val1},{key2,val2}}
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>l</b><br />
<b>location</b>
</td>
<td>
<p>
Used to output location information of the caller which generated the logging event.
</p>
<p>
The location information depends on the JVM implementation but usually consists of the fully
qualified name of the calling method followed by the callers source the file name and line
number between parentheses.
</p>
</td>
</tr>
<tr class="a">
<td align="center">
<b>L</b><br />
<b>line</b>
</td>
<td>Used to output the line number from where the logging request
was issued.
</td>
</tr>
<tr class="b">
<td align="center">
<b>m</b><br />
<b>msg</b><br />
<b>message</b>
</td>
<td>Used to output the application supplied message associated with the logging event.
</td>
</tr>
<tr class="a">
<td align="center">
<b>M</b><br />
<b>method</b>
</td>
<td>Used to output the method name where the logging request was issued.
</td>
</tr>
<tr class="b">
<td align="center">
<b>marker</b>
</td>
<td>The name of the marker, if one is present.</td>
</tr>
<tr class="a">
<td align="center">
<b>n</b>
</td>
<td>
<p>
Outputs the platform dependent line separator character or characters.
</p>
<p>This conversion character offers practically the same
performance as using non-portable line separator strings such as
&quot;\n&quot;, or &quot;\r\n&quot;. Thus, it is the preferred way of specifying a
line separator.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>p</b><br />
<b>level</b>
</td>
<td>Used to output the level of the logging event.</td>
</tr>
<tr class="a">
<td align="center">
<b>r</b><br />
<b>relative</b>
</td>
<td>Used to output the number of milliseconds elapsed since the JVM was started until the creation
of the logging event.
</td>
</tr>
<tr class="b">
<td align="center">
<b>replace</b>{pattern}{regex}{substitution}
</td>
<td>
<p>
Replaces occurrences of 'regex', a regular expression, with its replacement 'substitution' in the
string resulting from evaluation of the pattern. For example, &quot;%replace(%msg}{\s}{}&quot; will remove
all spaces contained in the event message.
</p>
<p>
The pattern can be arbitrarily complex and in particular can contain multiple conversion keywords.
For instance, &quot;%replace{%logger %msg}{\.}{/}&quot; will replace all dots in the logger or the message of
the event with a forward slash.
</p>
</td>
</tr>
<tr class="a">
<td align="center">
<b>rEx</b>{depth}<br />
<b>rException</b>{depth}<br />
<b>rThrowable</b>{depth}
</td>
<td>
<p>
The same as the %throwable conversion word but the stack trace is printed starting with the
first exception that was thrown followed by each subsequent wrapping exception.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>sn</b><br />
<b>sequenceNumber</b>
</td>
<td>Includes a sequence number that will be incremented in every event. The counter is a
static variable so will only be unique within applications that share the same converter Class
object.</td>
</tr>
<tr class="a">
<td align="center">
<b>t</b><br />
<b>thread</b>
</td>
<td>Used to output the name of the thread that generated the logging event.</td>
</tr>
<tr class="b">
<td align="center">
<b>x</b><br />
<b>NDC</b>
</td>
<td>Used to output the Thread Context Stack (also known as the Nested Diagnostic Context or NDC)
associated with the thread that generated the logging event.
</td>
</tr>
<tr class="a">
<td align="center">
<b>X</b>{key}<br />
<b>mdc</b>{key}<br />
<b>MDC</b>{key}
</td>
<td>
<p>Used to output the Thread Context Map (also known as the Mapped Diagnostic Context or MDC)
associated with the thread that generated the logging event. The
<b>X</b>
conversion character can be followed by the key for the
map placed between braces, as in
<b>%X{clientNumber}</b>
where
<tt>clientNumber</tt>
is the key. The value in the MDC
corresponding to the key will be output. If no additional sub-option
is specified, then the entire contents of the MDC key value pair set
is output using a format {{key1,val1},{key2,val2}}
</p>
<p>See the
<a href="../../log4j2-api/apidocs/org/apache/logging/log4j/ThreadContext.html">ThreadContext</a>
class for more details.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>u</b>{&quot;RANDOM&quot; | &quot;TIME&quot;}<br />
<b>uuid</b>
</td>
<td>Includes either a random or a time-based UUID. The time-based UUID is a Type 1 UUID that can
generate up to 10,000 unique ids per millisecond, will use the MAC address of each host, and to
try to insure uniqueness across multiple JVMs and/or ClassLoaders on the same host a
random number between 0 and 16,384 will be associated with each instance of the UUID generator
Class and included in each time-based UUID generated. Because time-based UUIDs contain
the MAC address and timestamp they should be used with care as they can cause a security
vulnerability.
</td>
</tr>
<tr class="a">
<td align="center">
<b>xEx</b>{depth}<br />
<b>xException</b>{depth}<br />
<b>xThrowable</b>{depth}
</td>
<td>
<p>
The same as the %throwable conversion word but also includes class packaging information.
</p>
<p>
At the end of each stack element of the exception, a string containing the name of the jar file
that contains the class or the directory the class is located in and the &quot;Implementation-Version&quot;
as found in that jar's manifest will be added. If the information is uncertain, then the class
packaging data will be preceded by a tilde, i.e. the '~' character.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>%</b>
</td>
<td>The sequence %% outputs a single percent sign.
</td>
</tr>
</table>
<p>By default the relevant information is output as is. However,
with the aid of format modifiers it is possible to change the
minimum field width, the maximum field width and justification.
</p>
<p>The optional format modifier is placed between the percent sign
and the conversion character.
</p>
<p>The first optional format modifier is the
<i>left justification
flag
</i>
which is just the minus (-) character. Then comes the
optional
<i>minimum field width</i>
modifier. This is a decimal
constant that represents the minimum number of characters to
output. If the data item requires fewer characters, it is padded on
either the left or the right until the minimum width is
reached. The default is to pad on the left (right justify) but you
can specify right padding with the left justification flag. The
padding character is space. If the data item is larger than the
minimum field width, the field is expanded to accommodate the
data. The value is never truncated.
</p>
<p>This behavior can be changed using the
<i>maximum field
width
</i>
modifier which is designated by a period followed by a
decimal constant. If the data item is longer than the maximum
field, then the extra characters are removed from the
<i>beginning</i>
of the data item and not from the end. For
example, it the maximum field width is eight and the data item is
ten characters long, then the first two characters of the data item
are dropped. This behavior deviates from the printf function in C
where truncation is done from the end.
</p>
<p>Below are various format modifier examples for the category
conversion specifier.
</p>
<table border="0" class="zebra-striped"><caption align="top">Pattern Converters</caption>
<tr class="a">
<th>Format modifier</th>
<th>left justify</th>
<th>minimum width</th>
<th>maximum width</th>
<th>comment</th>
</tr>
<tr class="b">
<td align="center">%20c</td>
<td align="center">false</td>
<td align="center">20</td>
<td align="center">none</td>
<td>Left pad with spaces if the category name is less than 20
characters long.
</td>
</tr>
<tr class="a">
<td align="center">%-20c</td>
<td align="center">true</td>
<td align="center">20
</td>
<td align="center">none</td>
<td>Right pad with
spaces if the category name is less than 20 characters long.
</td>
</tr>
<tr class="b">
<td align="center">%.30c</td>
<td align="center">NA</td>
<td align="center">none</td>
<td align="center">30</td>
<td>Truncate from the beginning if the category name is longer than 30
characters.
</td>
</tr>
<tr class="a">
<td align="center">%20.30c</td>
<td align="center">false</td>
<td align="center">20</td>
<td align="center">30</td>
<td>Left pad with spaces if the category name is shorter than 20
characters. However, if category name is longer than 30 characters,
then truncate from the beginning.
</td>
</tr>
<tr class="b">
<td align="center">%-20.30c</td>
<td align="center">true</td>
<td align="center">20</td>
<td align="center">30</td>
<td>Right pad with spaces if the category name is shorter than 20
characters. However, if category name is longer than 30 characters,
then truncate from the beginning.
</td>
</tr>
</table>
</div></div>
<a name="RFC5424Layout"></a>
<div class="section"><h3>RFC5424Layout<a name="RFC5424Layout"></a></h3>
<p>
As the name implies, the RFC5424Layout formats LogEvents in accordance with
<a class="externalLink" href="http://tools.ietf.org/html/rfc5424">RFC 5424</a>, the enhanced Syslog specification. Although the specification
is primarily directed at sending messages via Syslog, this format is quite useful for
other purposes since items are passed in the message as self-describing key/value pairs.
</p>
<table class="zebra-striped" border="1" width="100%"><caption align="top">RFC5424Layout Parameters</caption>
<tr class="a">
<th>Parameter Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr class="b">
<td>appName</td>
<td>String</td>
<td>The value to use as the APP-NAME in the RFC 5424 syslog record.</td>
</tr>
<tr class="a">
<td>charset</td>
<td>String</td>
<td>The character set to use when converting the syslog String to a byte array. The String must be
a valid <a class="externalLink" href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a>.
If not specified, the default system Charset will be used.</td>
</tr>
<tr class="b">
<td>enterpriseNumber</td>
<td>integer</td>
<td>The IANA enterprise number as described in
<a class="externalLink" href="http://tools.ietf.org/html/rfc5424#section-7.2.2">RFC 5424</a></td>
</tr>
<tr class="a">
<td>facility</td>
<td>String</td>
<td>The facility is used to try to classify the message. The facility option must be set to one of
&quot;KERN&quot;, &quot;USER&quot;, &quot;MAIL&quot;, &quot;DAEMON&quot;, &quot;AUTH&quot;, &quot;SYSLOG&quot;, &quot;LPR&quot;, &quot;NEWS&quot;, &quot;UUCP&quot;, &quot;CRON&quot;, &quot;AUTHPRIV&quot;,
&quot;FTP&quot;, &quot;NTP&quot;, &quot;AUDIT&quot;, &quot;ALERT&quot;, &quot;CLOCK&quot;, &quot;LOCAL0&quot;, &quot;LOCAL1&quot;, &quot;LOCAL2&quot;, &quot;LOCAL3&quot;, &quot;LOCAL4&quot;, &quot;LOCAL5&quot;,
&quot;LOCAL6&quot;, or &quot;LOCAL7&quot;. These values may be specified as upper or lower case characters.</td>
</tr>
<tr class="b">
<td>format</td>
<td>String</td>
<td>If set to &quot;RFC5424&quot; the data will be formatted in accordance with RFC 5424. Otherwise, it will
be formatted as a BSD Syslog record. Note that although BSD Syslog records are required to be
1024 bytes or shorter the SyslogLayout does not truncate them. The RFC5424Layout also does not
truncate records since the receiver must accept records of up to 2048 bytes and may accept records
that are longer.</td>
</tr>
<tr class="a">
<td>id</td>
<td>String</td>
<td>The default structured data id to use when formatting according to RFC 5424. If the LogEvent contains
a StructuredDataMessage the id from the Message will be used instead of this value.</td>
</tr>
<tr class="b">
<td>immediateFlush</td>
<td>boolean</td>
<td>When set to true, each write will be followed by a flush. This will guarantee the data is written
to disk but could impact performance.</td>
</tr>
<tr class="a">
<td>includeMDC</td>
<td>boolean</td>
<td>Indicates whether data from the ThreadContextMap will be included in the RFC 5424 Syslog record.
Defaults to true.</td>
</tr>
<tr class="b">
<td>mdcExcludes</td>
<td>String</td>
<td>A comma separated list of mdc keys that should be excluded from the LogEvent. This is mutually
exclusive with the mdcIncludes attribute. This attribute only applies to RFC 5424 syslog records.</td>
</tr>
<tr class="a">
<td>mdcIncludes</td>
<td>String</td>
<td>A comma separated list of mdc keys that should be included in the FlumeEvent. Any keys in the MDC
not found in the list will be excluded. This option is mutually exclusive with the mdcExcludes
attribute. This attribute only applies to RFC 5424 syslog records.</td>
</tr>
<tr class="b">
<td>mdcRequired</td>
<td>String</td>
<td>A comma separated list of mdc keys that must be present in the MDC. If a key is not present a
LoggingException will be thrown. This attribute only applies to RFC 5424 syslog records.</td>
</tr>
<tr class="a">
<td>mdcPrefix</td>
<td>String</td>
<td>A string that should be prepended to each MDC key in order to distinguish it from event attributes.
The default string is &quot;mdc:&quot;. This attribute only applies to RFC 5424 syslog records.</td>
</tr>
<tr class="b">
<td>messageId</td>
<td>String</td>
<td>The default value to be used in the MSGID field of RFC 5424 syslog records. </td>
</tr>
<tr class="a">
<td>newLine</td>
<td>boolean</td>
<td>If true, a newline will be appended to the end of the syslog record. The default is false.</td>
</tr>
</table>
</div>
<a name="SerializedLayout"></a>
<div class="section"><h3>SerializedLayout<a name="SerializedLayout"></a></h3>
<p>
The SerializedLayout simply serializes the LogEvent into a byte array. This is useful when
sending messages via JMS or via a Socket connection. The SerializedLayout accepts no parameters.
</p>
</div>
<a name="SyslogLayout"></a>
<div class="section"><h3>SyslogLayout<a name="SyslogLayout"></a></h3>
<p>
The SyslogLayout formats the LogEvent as BSD Syslog records matching the same format used by
Log4j 1.2.
</p>
<table class="zebra-striped" border="1" width="100%"><caption align="top">SyslogLayout Parameters</caption>
<tr class="a">
<th>Parameter Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr class="b">
<td>charset</td>
<td>String</td>
<td>The character set to use when converting the syslog String to a byte array. The String must be
a valid <a class="externalLink" href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a>.
If not specified, the default system Charset will be used.</td>
</tr>
<tr class="a">
<td>facility</td>
<td>String</td>
<td>The facility is used to try to classify the message. The facility option must be set to one of
&quot;KERN&quot;, &quot;USER&quot;, &quot;MAIL&quot;, &quot;DAEMON&quot;, &quot;AUTH&quot;, &quot;SYSLOG&quot;, &quot;LPR&quot;, &quot;NEWS&quot;, &quot;UUCP&quot;, &quot;CRON&quot;, &quot;AUTHPRIV&quot;,
&quot;FTP&quot;, &quot;NTP&quot;, &quot;AUDIT&quot;, &quot;ALERT&quot;, &quot;CLOCK&quot;, &quot;LOCAL0&quot;, &quot;LOCAL1&quot;, &quot;LOCAL2&quot;, &quot;LOCAL3&quot;, &quot;LOCAL4&quot;, &quot;LOCAL5&quot;,
&quot;LOCAL6&quot;, or &quot;LOCAL7&quot;. These values may be specified as upper or lower case characters.</td>
</tr>
<tr class="b">
<td>newLine</td>
<td>boolean</td>
<td>If true, a newline will be appended to the end of the syslog record. The default is false.</td>
</tr>
</table>
</div>
<a name="XMLLayout"></a>
<div class="section"><h3>XMLLayout<a name="XMLLayout"></a></h3>
<p>
The output of the XMLLayout consists of a series of log4j:event
elements as defined in the<a href="log4j.dtd">log4j.dtd</a>. If configured to do so it will
output a complete well-formed XML file. The output is designed to be
included as an
<i>external entity</i>
in a separate file to form
a correct XML file.
</p>
<p>For example, if <tt>abc</tt> is the name of the file where
the XMLLayout ouput goes, then a well-formed XML file would be:
</p>
<div><pre>
&lt;?xml version=&quot;1.0&quot; ?&gt;
*
&lt;!DOCTYPE log4j:eventSet SYSTEM &quot;log4j.dtd&quot; [&lt;!ENTITY data SYSTEM &quot;abc&quot;&gt;]&gt;
*
&lt;log4j:eventSet version=&quot;2.0&quot; xmlns:log4j=&quot;http://logging.apache.org/log4j/&quot;&gt;
&#160;&#160;
&lt;/log4j:eventSet&gt;
</pre></div>
<p>
This approach enforces the independence of the XMLLayout and the appender where it is embedded.
</p>
<p>
The <tt>version</tt> attribute helps components to correctly intrepret output generated by XMLLayout.
The value of this attribute should be &quot;2.0&quot;.
</p>
<p>
Appenders using this layout should have their encoding set to UTF-8 or UTF-16, otherwise events containing
non ASCII characters could result in corrupted log files.
</p>
</div>
</div>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row span16">Copyright &copy; 1999-2012
<a href="http://www.apache.org">Apache Software Foundation</a>.
All Rights Reserved.
</div>
</div>
</footer>
</body>
</html>