blob: 575d1bf1a629296fb976657e324a11bdd47ce24f [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
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.
-->
<!-- Generated by Apache Maven Doxia at Oct 19, 2014 -->
<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" />
<title>
Log4j 2 Layouts - Apache Log4j 2</title>
<link rel="stylesheet" href="../css/bootstrap.min.css" type="text/css" />
<link rel="stylesheet" href="../css/site.css" type="text/css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/prettify.min.js"></script>
<script type="text/javascript" src="../js/site.js"></script>
<meta name="author" content="Ralph Goers" />
<meta name="author" content="Gary Gregory" />
<meta name="Date-Revision-yyyymmdd" content="20141019" />
<meta http-equiv="Content-Language" content="en" />
</head>
<body class="composite">
<img class="logo-left" src="../images/ls-logo.jpg" alt="Apache logging services logo" />
<img class="logo-right" src="../images/logo.jpg" alt="Apache log4j logo" />
<div class="clear"></div>
<div class="navbar">
<div class="navbar-inner">
<div class="container-fluid">
<a class="brand" href="http://logging.apache.org/log4j/2.x/">Apache Log4j 2 &trade;</a>
<ul class="nav">
<li>
<a href="http://wiki.apache.org/logging" class="external" target="_blank" title="Logging Wiki">Logging Wiki</a>
</li>
<li>
<a href="http://www.apache.org/" class="external" target="_blank" title="Apache">Apache</a>
</li>
<li>
<a href="../../../" title="Logging Services">Logging Services</a>
</li>
<li>
<a href="https://analysis.apache.org/dashboard/index/org.apache.logging.log4j:log4j" class="external" target="_blank" title="Sonar">Sonar</a>
</li>
</ul>
</div>
</div>
</div>
<div class="container-fluid">
<table class="layout-table">
<tr>
<td class="sidebar">
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-home"></i>Apache Log4j™ 2</li>
<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="../maven-artifacts.html" title="Maven and Ivy">Maven and Ivy</a>
</li>
<li class="none">
<a href="../build.html" title="Build">Build</a>
</li>
<li class="none">
<a href="../guidelines.html" title="Guidelines">Guidelines</a>
</li>
<li class="none">
<a href="../javastyle.html" title="Style Guide">Style Guide</a>
</li>
<li class="none">
<a href="../changelog.html" title="Changelog">Changelog</a>
</li>
<li class="collapsed">
<a href="../javadoc.html" title="Javadoc">Javadoc</a>
</li>
<li class="none">
<a href="../runtime-dependencies.html" title="Runtime Dependencies">Runtime Dependencies</a>
</li>
<li class="none">
<a href="../faq.html" title="FAQ">FAQ</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-book"></i>Manual</li>
<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="none">
<a href="../manual/migration.html" title="Log4j 1.x Migration">Log4j 1.x Migration</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/webapp.html" title="Web Applications and JSPs">Web Applications and JSPs</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 active">
<a href="../manual/layouts.html" title="Layouts">Layouts</a>
<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="RFC-5424">RFC-5424</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>
<li class="none">
<a href="../manual/layouts.html#LocationInformation" title="Location Information">Location Information</a>
</li>
</ul>
</li>
<li class="collapsed">
<a href="../manual/filters.html" title="Filters">Filters</a>
</li>
<li class="collapsed">
<a href="../manual/async.html" title="Async Loggers">Async Loggers</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>
<li class="collapsed">
<a href="../manual/customconfig.html" title="Extending Log4j Configuration">Extending Log4j Configuration</a>
</li>
<li class="collapsed">
<a href="../manual/customloglevels.html" title="Custom Log Levels">Custom Log Levels</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Components</li>
<li class="none">
<a href="../log4j-api/index.html" title="API">API</a>
</li>
<li class="none">
<a href="../log4j-core/index.html" title="Implementation">Implementation</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="../log4j-1.2-api/index.html" title="Log4j 1.2 API">Log4j 1.2 API</a>
</li>
<li class="none">
<a href="../log4j-slf4j-impl/index.html" title="SLF4J Binding">SLF4J Binding</a>
</li>
<li class="none">
<a href="../log4j-jul/index.html" title="JUL Adapter">JUL Adapter</a>
</li>
<li class="none">
<a href="../log4j-to-slf4j/index.html" title="Log4j 2 to SLF4J Adapter">Log4j 2 to SLF4J Adapter</a>
</li>
<li class="none">
<a href="../log4j-flume-ng/index.html" title="Apache Flume NG Appender">Apache Flume NG Appender</a>
</li>
<li class="none">
<a href="../log4j-taglib/index.html" title="Log4j Tag Library">Log4j Tag Library</a>
</li>
<li class="none">
<a href="../log4j-jmx-gui/index.html" title="Log4j JMX GUI">Log4j JMX GUI</a>
</li>
<li class="none">
<a href="../log4j-web/index.html" title="Log4j Web Application Support">Log4j Web Application Support</a>
</li>
<li class="none">
<a href="../log4j-nosql/index.html" title="Log4j NoSQL support">Log4j NoSQL support</a>
</li>
<li class="none">
<a href="../log4j-iostreams/index.html" title="Log4j IO Streams">Log4j IO Streams</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-info-sign"></i>Project Information</li>
<li class="none">
<a href="../dependencies.html" title="Dependencies">Dependencies</a>
</li>
<li class="none">
<a href="../dependency-convergence.html" title="Dependency Convergence">Dependency Convergence</a>
</li>
<li class="none">
<a href="../dependency-management.html" title="Dependency Management">Dependency Management</a>
</li>
<li class="none">
<a href="../team-list.html" title="Project Team">Project Team</a>
</li>
<li class="none">
<a href="../mail-lists.html" title="Mailing Lists">Mailing Lists</a>
</li>
<li class="none">
<a href="../issue-tracking.html" title="Issue Tracking">Issue Tracking</a>
</li>
<li class="none">
<a href="../license.html" title="Project License">Project License</a>
</li>
<li class="none">
<a href="../source-repository.html" title="Source Repository">Source Repository</a>
</li>
<li class="none">
<a href="../project-summary.html" title="Project Summary">Project Summary</a>
</li>
</ul>
<ul class="nav nav-list">
<li class="nav-header"><i class="icon-cog"></i>Project Reports</li>
<li class="none">
<a href="../changes-report.html" title="Changes Report">Changes Report</a>
</li>
<li class="none">
<a href="../jira-report.html" title="JIRA Report">JIRA Report</a>
</li>
<li class="none">
<a href="../surefire-report.html" title="Surefire Report">Surefire Report</a>
</li>
<li class="none">
<a href="../rat-report.html" title="RAT Report">RAT Report</a>
</li>
</ul>
</div>
<div id="poweredBy">
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
<img class="poweredBy" alt="Built by Maven" src="../images/maven-feather.png" />
</a>
</div>
</td>
<td class="content">
<!-- 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>An Appender uses a Layout to format a LogEvent into a form that meets the needs of whatever will be
consuming the log event. 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 you need to configure most Layouts with a <a class="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a> to
ensure the byte array contains correct values.
</p>
<a name="JSONLayout"></a>
<div class="section"><h3>JSONLayout<a name="JSONLayout"></a></h3>
<!-- From Javadoc of org.apache.logging.log4j.core.layout.JSONLayout -->
<p>
Appends a series of JSON events as strings serialized as bytes. This layout requires Jackson jar files
(see pom.xml for details).
</p>
<div class="section"><h4>Complete well-formed JSON vs. fragment JSON<a name="Complete_well-formed_JSON_vs._fragment_JSON"></a></h4>
<p>
If you configure <tt>complete=&quot;true&quot;</tt>, the appender outputs a well-formed JSON document. By default,
with <tt>complete=&quot;false&quot;</tt>, you should include the output as an <i>external file</i> in a
separate file to form a well-formed JSON document.
</p>
<p>
A well-formed JSON document follows this pattern:
</p>
<div class="prettyprint linenums"><pre>[
{
&quot;logger&quot;:&quot;com.foo.Bar&quot;,
&quot;timestamp&quot;:&quot;1376681196470&quot;,
&quot;level&quot;:&quot;INFO&quot;,
&quot;thread&quot;:&quot;main&quot;,
&quot;message&quot;:&quot;Message flushed with immediate flush=true&quot;
},
{
&quot;logger&quot;:&quot;com.foo.Bar&quot;,
&quot;timestamp&quot;:&quot;1376681196471&quot;,
&quot;level&quot;:&quot;ERROR&quot;,
&quot;thread&quot;:&quot;main&quot;,
&quot;message&quot;:&quot;Message flushed with immediate flush=true&quot;,
&quot;throwable&quot;:&quot;java.lang.IllegalArgumentException: badarg\\n\\tat org.apache.logging.log4j.core.appender.JSONCompleteFileAppenderTest.testFlushAtEndOfBatch(JSONCompleteFileAppenderTest.java:54)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\\n\\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)\\n\\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n\\tat java.lang.reflect.Method.invoke(Method.java:606)\\n\\tat org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)\\n\\tat org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)\\n\\tat org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)\\n\\tat org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)\\n\\tat org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)\\n\\tat org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)\\n\\tat org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)\\n\\tat org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)\\n\\tat org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)\\n\\tat org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)\\n\\tat org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)\\n\\tat org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)\\n\\tat org.junit.runners.ParentRunner.run(ParentRunner.java:309)\\n\\tat org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)\\n\\tat org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)\\n\\tat org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)\\n&quot;
}
]
</pre></div>
<p>
If <tt>complete=&quot;false&quot;</tt>, the appender does not write the JSON open array character &quot;[&quot; at the start
of the document. and &quot;]&quot; and the end.
</p>
<p>
This approach enforces the independence of the JSONLayout and the appender where you embed it.
</p>
</div><div class="section"><h4>Encoding<a name="Encoding"></a></h4>
<p>
Appenders using this layout should have their <tt>charset</tt> set to <tt>UTF-8</tt> or
<tt>UTF-16</tt>, otherwise events containing non-ASCII characters could result in corrupted log files.
The default charset is <tt>UTF-8</tt>.
</p>
</div><div class="section"><h4>Pretty vs. compact JSON<a name="Pretty_vs._compact_JSON"></a></h4>
<p>
By default, the JSON layout is not compact (a.k.a. not &quot;pretty&quot;) with <tt>compact=&quot;false&quot;</tt>, which
means the appender uses end-of-line characters and indents lines to format the text. If
<tt>compact=&quot;true&quot;</tt>, then no end-of-line or indentation is used. Message content may contain,
of course, escaped end-of-lines.
</p>
<table border="0" class="bodyTable"><caption align="top">JSON 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="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Charset</a>. If not specified, UTF-8 will be used.</td>
</tr>
<tr class="a">
<td>compact</td>
<td>boolean</td>
<td>If true, the appender does not use end-of-lines and indentation. Defaults to false.</td>
</tr>
<tr class="b">
<td>complete</td>
<td>boolean</td>
<td>If true, the appender includes the JSON header and footer. Defaults to false.</td>
</tr>
<tr class="a">
<td>properties</td>
<td>boolean</td>
<td>If true, the appender includes the thread context in the generated JSON. Defaults to false.</td>
</tr>
<tr class="b">
<td>locationInfo</td>
<td>boolean</td>
<td>
<p>If true, the appender includes the location information in the generated JSON. Defaults to false.</p>
<p>Generating <a href="#LocationInformation">location information</a>
is an expensive operation and may impact performance. Use with caution.</p>
</td>
</tr>
</table>
</div></div>
<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 border="0" class="bodyTable"><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="javadoc" href="http://docs.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>
<a name="HtmlLocationInfo"></a>
<p>If true, the filename and line number will be included in the HTML output. The default value is
false.</p>
<p>Generating <a href="#LocationInformation">location information</a>
is an expensive operation and may impact performance. Use with caution.</p>
</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, including <b>Special Characters</b>, may be included in the conversion
pattern.</i> Special Characters include <b>\t</b>, <b>\n</b>, <b>\r</b>, <b>\f</b>. Use <b>\\</b> to
insert a single backslash into the output.
</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>
<p>
If the pattern string does not contain a specifier to handle a Throwable being logged, parsing of the
pattern will act as if the &quot;%xEx&quot; specifier had be added to the end of the string. To suppress
formatting of the Throwable completely simply add &quot;%ex{0}&quot; as a specifier in the pattern string.
</p>
<table border="0" class="bodyTable"><caption align="top">PatternLayout 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="javadoc" href="http://docs.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>A composite pattern string of one or more conversion patterns from the table below.</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>
<tr class="a">
<td>alwaysWriteExceptions</td>
<td>boolean</td>
<td>If <tt>true</tt> (it is by default) exceptions are always written even if the pattern contains no
exception conversions. This means that if you do not include a way to output exceptions in your pattern,
the default exception formatter will be added to the end of the pattern. Setting this to
<tt>false</tt> disables this behavior and allows you to exclude exceptions from your pattern
output.</td>
</tr>
<tr class="b">
<td>header</td>
<td>String</td>
<td>The optional header string to include at the top of each log file.</td>
</tr>
<tr class="a">
<td>footer</td>
<td>String</td>
<td>The optional footer string to include at the bottom of each log file.</td>
</tr>
<tr class="b">
<td>noConsoleNoAnsi</td>
<td>boolean</td>
<td>If <tt>true</tt> (default is false) and <tt>System.console()</tt> is null, do not output ANSI escape codes.</td>
</tr>
</table>
<table border="0" class="bodyTable"><caption align="top">RegexReplacement Parameters</caption>
<tr class="a">
<th>Parameter Name</th>
<th>Type</th>
<th>Description</th>
</tr>
<tr class="b">
<td>regex</td>
<td>String</td>
<td>A Java-compliant regular expression to match in the resulting string. See
<a class="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html">Pattern</a>
.</td>
</tr>
<tr class="a">
<td>replacement</td>
<td>String</td>
<td>The string to replace any matched sub-strings with.</td>
</tr>
</table>
<div class="section"><h4>Patterns<a name="Patterns"></a></h4>
<p>The conversions that are provided with Log4j are:
</p>
<table border="0" class="bodyTable">
<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>Outputs 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 border="0" class="bodyTable">
<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">
<a name="PatternClass"></a>
<b>C</b>{precision}<br />
<b>class</b>{precision}
</td>
<td>
<p>Outputs 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>
<p>Generating the class name of the caller (<a href="#LocationInformation">location information</a>)
is an expensive operation and may impact performance. Use with caution.</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>d</b>{pattern}<br />
<b>date</b>{pattern}
</td>
<td>
<p>Outputs the date of the logging event. The date conversion specifier may be
followed by a set of braces containing a date and time pattern string per
<a class="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html">SimpleDateFormat</a>
.
</p>
<p>The predefined formats are
<tt>DEFAULT</tt>,
<tt>ABSOLUTE</tt>,
<tt>COMPACT</tt>,
<tt>DATE</tt>,
<tt>ISO8601</tt>,
and
<tt>ISO8601_BASIC</tt>.
</p>
<p>You can also use a set of braces containing a time zone id per
<a class="javadoc" href="http://docs.oracle.com/javase/6/docs/api/java/util/TimeZone.html#getTimeZone(java.lang.String)">
java.util.TimeZone.getTimeZone</a>. If no date format specifier is given then ISO8601 format is assumed.
</p><table border="0" class="bodyTable">
<tr class="a">
<th>Pattern</th>
<th>Example</th>
</tr>
<tr class="b">
<td>%d{DEFAULT}</td>
<td>2012-11-02 14:34:02,781</td>
</tr>
<tr class="a">
<td>%d{ISO8601}</td>
<td>2012-11-02T14:34:02,781</td>
</tr>
<tr class="b">
<td>%d{ISO8601_BASIC}</td>
<td>20121102T143402,781</td>
</tr>
<tr class="a">
<td>%d{ABSOLUTE}</td>
<td>14:34:02,781</td>
</tr>
<tr class="b">
<td>%d{DATE}</td>
<td>02 Nov 2012 14:34:02,781</td>
</tr>
<tr class="a">
<td>%d{COMPACT}</td>
<td>20121102143402781</td>
</tr>
<tr class="b">
<td>%d{HH:mm:ss,SSS}</td>
<td>14:34:02,781</td>
</tr>
<tr class="a">
<td>%d{dd MMM yyyy HH:mm:ss,SSS}</td>
<td>02 Nov 2012 14:34:02,781</td>
</tr>
<tr class="b">
<td>%d{HH:mm:ss}{GMT+0}</td>
<td>18:34:02</td>
</tr>
<tr class="a">
<td>%d{UNIX}</td>
<td>1351866842</td>
</tr>
<tr class="b">
<td>%d{UNIX_MILLIS}</td>
<td>1351866842781</td>
</tr>
</table>
<p>
%d{UNIX} outputs the UNIX time in seconds. %d{UNIX_MILLIS} outputs the UNIX time in milliseconds.
The UNIX time is the difference, in seconds for UNIX and in milliseconds for UNIX_MILLIS, between
the current time and midnight, January 1, 1970 UTC. While the time unit is milliseconds, the
granularity depends on the operating system
(<a class="externalLink" href="http://msdn.microsoft.com/en-us/windows/hardware/gg463266.aspx">Windows</a>).
This is an efficient way to output the event time because only a conversion from long to String
takes place, there is no Date formatting involved.
</p>
</td>
</tr>
<tr class="a">
<td align="center">
<b>enc</b>{pattern}<br />
<b>encode</b>{pattern&gt;
</td>
<td>
<p>Escape newlines and HTML special characters in the specified pattern.
</p>
<p>Allows HTML to be safely logged.</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>enc{pattern}</b><br />
<b>encode{pattern}</b>
</td>
<td>
<p>
Encodes special characters such as '\n' and HTML characters to help prevent log forging
and some XSS attacks that could occur when displaying logs in a web browser. Anytime
user provided data is logged, this can provide a safeguard.
</p>
<p>
A typical usage would encode the message
</p><div><pre>%enc{%m}</pre></div>
but user input could come from other locations as well, such as the MDC
<div><pre>%enc{%mdc{key}}</pre></div>
<p>The replaced characters are:
</p><table border="0" class="bodyTable">
<tr class="a">
<th>Character</th>
<th>Replacement</th>
</tr>
<tr class="b">
<th>'\r', '\n'</th>
<th>Removed from the pattern</th>
</tr>
<tr class="a">
<td>&amp;, &lt;, &gt;, &quot;, ', /</td>
<td>Replaced with the corresponding HTML entity</td>
</tr>
</table>
</td>
</tr>
<tr class="a">
<td align="center">
<b>ex</b>|<b>exception</b>|<b>throwable</b><br />
&#160;&#160;{[&quot;none&quot;<br />
&#160;&#160;|&quot;full&quot;<br />
&#160;&#160;|depth<br />
&#160;&#160;|&quot;short&quot;<br />
&#160;&#160;|&quot;short.className&quot;<br />
&#160;&#160;|&quot;short.fileName&quot;<br />
&#160;&#160;|&quot;short.lineNumber&quot;<br />
&#160;&#160;|&quot;short.methodName&quot;<br />
&#160;&#160;|&quot;short.message&quot;<br />
&#160;&#160;|&quot;short.localizedMessage&quot;]}
</td>
<td>
<p>
Outputs the Throwable trace bound to the LoggingEvent, by default this will output the full trace
as one would normally find with a call to Throwable.printStackTrace().
</p>
<p>
You can follow the throwable conversion word with an option in the form <b>%throwable{option}</b>.
</p>
<p>
<b>%throwable{short}</b> outputs the first line of the Throwable.
</p>
<p>
<b>%throwable{short.className}</b> outputs the name of the class where the exception occurred.
</p>
<p>
<b>%throwable{short.methodName}</b> outputs the method name where the exception occurred.
</p>
<p>
<b>%throwable{short.fileName}</b> outputs the name of the class where the exception occurred.
</p>
<p>
<b>%throwable{short.lineNumber}</b> outputs the line number where the exception occurred.
</p>
<p>
<b>%throwable{short.message}</b> outputs the message.
</p>
<p>
<b>%throwable{short.localizedMessage}</b> outputs the localized message.
</p>
<p>
<b>%throwable{n}</b> outputs the first n lines of the stack trace.
</p>
<p>
Specifying <b>%throwable{none}</b> or <b>%throwable{0}</b> suppresses output of the exception.
</p>
</td>
</tr>
<tr class="b">
<td align="center">
<a name="PatternFile"></a>
<b>F</b><br />
<b>file</b>
</td>
<td><p>Outputs the file name where the logging request was issued.</p>
<p>Generating the file information (<a href="#LocationInformation">location information</a>)
is an expensive operation and may impact performance. Use with caution.</p>
</td>
</tr>
<tr class="a">
<td align="center">
<b>highlight</b>{pattern}{style}
</td>
<td>
<p>Adds ANSI colors to the result of the enclosed pattern based on the current event's logging level.
</p>
<p>The default colors for each level are:
</p><table border="0" class="bodyTable">
<tr class="b">
<th>Level</th>
<th>ANSI color</th>
</tr>
<tr class="a">
<td>FATAL</td>
<td>Bright red</td>
</tr>
<tr class="b">
<td>ERROR</td>
<td>Bright red</td>
</tr>
<tr class="a">
<td>WARN</td>
<td>Yellow</td>
</tr>
<tr class="b">
<td>INFO</td>
<td>Green</td>
</tr>
<tr class="a">
<td>DEBUG</td>
<td>Cyan</td>
</tr>
<tr class="b">
<td>TRACE</td>
<td>Black (looks dark grey)</td>
</tr>
</table>
<p>The color names are ANSI names defined in the
<a href="../log4j-core/apidocs/org/apache/logging/log4j/core/pattern/AnsiEscape.html" class="javadoc">AnsiEscape</a> class.
</p>
<p>The color and attribute names and are standard, but the exact shade, hue, or value.
</p>
<table border="0" class="bodyTable"><caption>Color table</caption>
<tbody>
<tr class="a">
<th>Intensity Code</th>
<th>0</th>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
<th>5</th>
<th>6</th>
<th>7</th>
</tr>
<tr class="b">
<th>Normal</th>
<td style="background: black;color:white">Black</td>
<td style="background: maroon;color:white">Red</td>
<td style="background: green;color:white">Green</td>
<td style="background: olive;color:white">Yellow</td>
<td style="background: navy;color:white">Blue</td>
<td style="background: purple;color:white">Magenta</td>
<td style="background: teal;color:white">Cyan</td>
<td style="background: silver;color:black">White</td>
</tr>
<tr class="a">
<th>Bright</th>
<td style="background: gray;color:white">Black</td>
<td style="background: red;color:black">Red</td>
<td style="background: lime;color:black">Green</td>
<td style="background: yellow;color:black">Yellow</td>
<td style="background: blue;color:white">Blue</td>
<td style="background: fuchsia;color:black">Magenta</td>
<td style="background: cyan;color:black">Cyan</td>
<td style="background: white;color:black">White</td>
</tr>
</tbody>
</table>
<p>You can use the default colors with:
</p><div><pre>%highlight{%d [%t] %-5level: %msg%n%throwable}</pre></div>
<p>You can override the default colors in the optional {style} option. For example:
</p><div><pre>%highlight{%d [%t] %-5level: %msg%n%throwable}{FATAL=white, ERROR=red, WARN=blue, INFO=black, DEBUG=green, TRACE=blue}</pre></div>
<p>You can highlight only the a portion of the log event:
</p><div><pre>%d [%t] %highlight{%-5level: %msg%n%throwable}</pre></div>
<p>You can style one part of the message and highlight the rest the log event:
</p><div><pre>%style{%d [%t]}{black} %highlight{%-5level: %msg%n%throwable}</pre></div>
<p>You can also use the STYLE key to use a predefined group of colors:
</p><div><pre>%highlight{%d [%t] %-5level: %msg%n%throwable}{STYLE=Logback}</pre></div>
The STYLE value can be one of:
<table border="0" class="bodyTable">
<tr class="a">
<th>Style</th>
<th>Description</th>
</tr>
<tr class="b">
<td>Default</td>
<td>See above</td>
</tr>
<tr class="a">
<td>Logback</td>
<td>
<table border="0" class="bodyTable">
<tr class="b">
<th>Level</th>
<th>ANSI color</th>
</tr>
<tr class="a">
<td>FATAL</td>
<td>Blinking bright red</td>
</tr>
<tr class="b">
<td>ERROR</td>
<td>Bright red</td>
</tr>
<tr class="a">
<td>WARN</td>
<td>Red</td>
</tr>
<tr class="b">
<td>INFO</td>
<td>Blue</td>
</tr>
<tr class="a">
<td>DEBUG</td>
<td>Normal</td>
</tr>
<tr class="b">
<td>TRACE</td>
<td>Normal</td>
</tr>
</table>
</td>
</tr>
</table>
</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>Outputs the entries in a
<a href="../log4j-api/apidocs/org/apache/logging/log4j/message/MapMessage.html" class="javadoc">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">
<a name="PatternLocation"></a>
<b>l</b><br />
<b>location</b>
</td>
<td>
<p>Outputs 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>
<p>Generating <a href="#LocationInformation">location information</a>
is an expensive operation and may impact performance. Use with caution.</p>
</td>
</tr>
<tr class="a">
<td align="center">
<a name="PatternLine"></a>
<b>L</b><br />
<b>line</b>
</td>
<td><p>Outputs the line number from where the logging request
was issued.</p>
<p>Generating line number information (<a href="#LocationInformation">location information</a>)
is an expensive operation and may impact performance. Use with caution.</p>
</td>
</tr>
<tr class="b">
<td align="center">
<b>m</b><br />
<b>msg</b><br />
<b>message</b>
</td>
<td>Outputs the application supplied message associated with the logging event.
</td>
</tr>
<tr class="a">
<td align="center">
<a name="PatternMethod"></a>
<b>M</b><br />
<b>method</b>
</td>
<td><p>Outputs the method name where the logging request was issued.</p>
<p>Generating the method name of the caller (<a href="#LocationInformation">location information</a>)
is an expensive operation and may impact performance. Use with caution.</p>
</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>|<b>level</b>{<i>level</i>=<i>label</i>, <i>level</i>=<i>label</i>, ...}
<b>p</b>|<b>level</b>{length=<i>n</i>}
<b>p</b>|<b>level</b>{lowerCase=<i>true</i>|<i>false</i>}
</td>
<td>
<p>
Outputs the level of the logging event. You provide a level name map in the form
&quot;level=value, level=value&quot; where level is the name of the Level and value is the value that
should be displayed instead of the name of the Level.
</p>
<p>
For example:
</p><div><pre>%level{WARN=Warning, DEBUG=Debug, ERROR=Error, TRACE=Trace, INFO=Info}</pre></div>
<p>
Alternatively, for the compact-minded:
</p><div><pre>%level{WARN=W, DEBUG=D, ERROR=E, TRACE=T, INFO=I}</pre></div>
<p>
More succinctly, for the same result as above, you can define the length of the level label:
</p><div><pre>%level{length=1}</pre></div>
If the length is greater than a level name length, the layout uses the normal level name.
<p>
You can combine the two kinds of options:
</p><div><pre>%level{ERROR=Error, length=2}</pre></div>
This give you the <tt>Error</tt> level name and all other level names of length 2.
<p>
Finally, you can output lower-case level names (the default is upper-case):
</p><div><pre>%level{lowerCase=true}</pre></div>
</td>
</tr>
<tr class="a">
<td align="center">
<b>r</b><br />
<b>relative</b>
</td>
<td>Outputs 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>[&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}<br />
<b>rException</b>[&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}<br />
<b>rThrowable</b>[&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}
</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>
<p>The throwable conversion word can be followed by an option in the form
<b>%rEx{short}</b>
which will only output the first line of the Throwable or <b>%rEx{n}</b> where
the first n lines of the stacktrace will be printed. The conversion word can also be
followed by &quot;filters(packages)&quot; where packages is a list of package names that should
be suppressed from stack traces. Specifying <b>%rEx{none}</b>
or <b>%rEx{0}</b> will suppress printing of the 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>style</b>{pattern}{ANSI style}
</td>
<td>
<p>Uses ANSI escape sequences to style the result of the enclosed pattern. The style can consist of
a comma separated list of style names from the following table.
</p><table border="0" class="bodyTable">
<tr class="b">
<th>Style Name</th>
<th>Description</th>
</tr>
<tr class="a">
<td>Normal</td>
<td>Normal display</td>
</tr>
<tr class="b">
<td>Bright</td>
<td>Bold</td>
</tr>
<tr class="a">
<td>Dim</td>
<td>Dimmed or faint characters</td>
</tr>
<tr class="b">
<td>Underline</td>
<td>Underlined characters</td>
</tr>
<tr class="a">
<td>Blink</td>
<td>Blinking characters</td>
</tr>
<tr class="b">
<td>Reverse</td>
<td>Reverse video</td>
</tr>
<tr class="a">
<td>Hidden</td>
<td></td>
</tr>
<tr class="b">
<td>Black or FG_Black</td>
<td>Set foreground color to black</td>
</tr>
<tr class="a">
<td>Red or FG_Red</td>
<td>Set foreground color to red</td>
</tr>
<tr class="b">
<td>Green or FG_Green</td>
<td>Set foreground color to green</td>
</tr>
<tr class="a">
<td>Yellow or FG_Yellow</td>
<td>Set foreground color to yellow</td>
</tr>
<tr class="b">
<td>Blue or FG_Blue</td>
<td>Set foreground color to blue</td>
</tr>
<tr class="a">
<td>Magenta or FG_Magenta</td>
<td>Set foreground color to magenta</td>
</tr>
<tr class="b">
<td>Cyan or FG_Cyan</td>
<td>Set foreground color to cyan</td>
</tr>
<tr class="a">
<td>White or FG_White</td>
<td>Set foreground color to white</td>
</tr>
<tr class="b">
<td>Default or FG_Default</td>
<td>Set foreground color to default (white)</td>
</tr>
<tr class="a">
<td>BG_Black</td>
<td>Set background color to black</td>
</tr>
<tr class="b">
<td>BG_Red</td>
<td>Set background color to red</td>
</tr>
<tr class="a">
<td>BG_Green</td>
<td>Set background color to green</td>
</tr>
<tr class="b">
<td>BG_Yellow</td>
<td>Set background color to yellow</td>
</tr>
<tr class="a">
<td>BG_Blue</td>
<td>Set background color to blue</td>
</tr>
<tr class="b">
<td>BG_Magenta</td>
<td>Set background color to magenta</td>
</tr>
<tr class="a">
<td>BG_Cyan</td>
<td>Set background color to cyan</td>
</tr>
<tr class="b">
<td>BG_White</td>
<td>Set background color to white</td>
</tr>
</table>
<p>For example:
</p><div><pre>%style{%d{ISO8601}}{black} %style{[%t]}{blue} %style{%-5level:}{yellow} %style{%msg%n%throwable}{green}</pre></div>
<p>You can also combine styles:
</p><div><pre>%d %highlight{%p} %style{%logger}{bright,cyan} %C{1.} %msg%n</pre></div>
<p>You can also use <tt>%</tt> with a color like <tt>%black</tt>, <tt>%blue</tt>, <tt>%cyan</tt>, and so on. For example:
</p><div><pre>%black{%d{ISO8601}} %blue{[%t]} %yellow{%-5level:} %green{%msg%n%throwable}</pre></div>
</td>
</tr>
<tr class="a">
<td align="center">
<b>t</b><br />
<b>thread</b>
</td>
<td>Outputs 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>Outputs 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>Outputs 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="../log4j-api/apidocs/org/apache/logging/log4j/ThreadContext.html" class="javadoc">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>{&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}<br />
<b>xException</b>[&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}<br />
<b>xThrowable</b>[&quot;none&quot;|&quot;short&quot;|&quot;full&quot;|depth],[filters(packages)}
</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>
<p>The throwable conversion word can be followed by an option in the form
<b>%xEx{short}</b>
which will only output the first line of the Throwable or <b>%xEx{n}</b> where
the first n lines of the stacktrace will be printed. The conversion word can also be
followed by &quot;filters(packages)&quot; where packages is a list of package names that should
be suppressed from stack traces. Specifying <b>%xEx{none}</b>
or <b>%xEx{0}</b> will suppress printing of the exception.
</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="bodyTable"><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 class="section"><h4>ANSI Styling on Windows<a name="ANSI_Styling_on_Windows"></a></h4>
<p>ANSI escape sequences are supported natively on many platforms but are not by default on Windows. To
enable ANSI support simply add the <a class="externalLink" href="http://jansi.fusesource.org/">Jansi</a> jar to your
application and Log4j will automatically make use of it when writing to the console.
</p>
</div><div class="section"><h4>Example Patterns<a name="Example_Patterns"></a></h4>
<div class="section"><h5>Filtered Throwables<a name="Filtered_Throwables"></a></h5>
<p>This example shows how to filter out classes from unimportant packages in stack traces.
</p>
<div class="prettyprint linenums"><pre>&lt;properties&gt;
&lt;property name=&quot;filters&quot;&gt;org.junit,org.apache.maven,sun.reflect,java.lang.reflect&lt;/property&gt;
&lt;/properties&gt;
...
&lt;PatternLayout pattern=&quot;%m%xEx{filters(${filters})}%n&quot;/&gt;</pre></div>
<p>The result printed to the console will appear similar to:
</p>
<div><pre>Exception java.lang.IllegalArgumentException: IllegalArgument
at org.apache.logging.log4j.core.pattern.ExtendedThrowableTest.testException(ExtendedThrowableTest.java:72) [test-classes/:?]
... suppressed 26 lines
at $Proxy0.invoke(Unknown Source)} [?:?]
... suppressed 3 lines
Caused by: java.lang.NullPointerException: null pointer
at org.apache.logging.log4j.core.pattern.ExtendedThrowableTest.testException(ExtendedThrowableTest.java:71) ~[test-classes/:?]
... 30 more</pre></div>
</div><div class="section"><h5>ANSI Styled<a name="ANSI_Styled"></a></h5>
<p>The log level will be highlighted according to the event's log level. All the content that follows
the level will be bright green.</p>
<div class="prettyprint linenums"><pre>&lt;PatternLayout&gt;
&lt;pattern&gt;%d %highlight{%p} %style{%C{1.} [%t] %m}{bold,green}%n&lt;/pattern&gt;
&lt;/PatternLayout&gt;</pre></div>
</div></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 border="0" class="bodyTable"><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="javadoc" href="http://docs.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>exceptionPattern</td>
<td>String</td>
<td>One of the conversion specifiers from PatternLayout that defines which ThrowablePatternConverter
to use to format exceptions. Any of the options that are valid for those specifiers may be included.
The default is to not include the Throwable from the event, if any, in the output.</td>
</tr>
<tr class="b">
<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="a">
<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="b">
<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="a">
<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="b">
<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="a">
<td>loggerFields</td>
<td>List of KeyValuePairs</td>
<td>Allows arbitrary PatternLayout patterns to be included as specified ThreadContext fields; no default
specified. To use, include a &lt;LoggerFields&gt; nested element, containing one or more
&lt;KeyValuePair&gt; elements. Each &lt;KeyValuePair&gt; must have a key attribute, which
specifies the key name which will be used to identify the field within the MDC Structured Data element,
and a value attribute, which specifies the PatternLayout pattern to use as the value.</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>
<tr class="b">
<td>newLineEscape</td>
<td>String</td>
<td>String that should be used to replace newlines within the message text.</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 border="0" class="bodyTable"><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="javadoc" href="http://docs.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>
<tr class="a">
<td>newLineEscape</td>
<td>String</td>
<td>String that should be used to replace newlines within the message text.</td>
</tr>
</table>
</div>
<a name="XMLLayout"></a>
<div class="section"><h3>XMLLayout<a name="XMLLayout"></a></h3>
<!-- From Javadoc of org.apache.logging.log4j.core.layout.XMLLayout -->
<p>
<!-- FIXME: log4j.dtd link is broken -->
Appends a series of <tt>Event</tt> elements as defined in the <a href="log4j.dtd">log4j.dtd</a>.
</p>
<div class="section"><h4>Complete well-formed XML vs. fragment XML<a name="Complete_well-formed_XML_vs._fragment_XML"></a></h4>
<p>
If you configure <tt>complete=&quot;true&quot;</tt>, the appender outputs a well-formed XML document where the
default namespace is the Log4j namespace <tt>&quot;http://logging.apache.org/log4j/2.0/events&quot;</tt>. By default,
with <tt>complete=&quot;false&quot;</tt>, you should include the output as an <i>external entity</i> in a
separate file to form a well-formed XML document, in which case the appender uses
<tt>namespacePrefix</tt> with a default of <tt>&quot;log4j&quot;</tt>.
</p>
<p>
A well-formed XML document follows this pattern:
</p>
<div class="prettyprint linenums"><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Events xmlns=&quot;http://logging.apache.org/log4j/2.0/events&quot;&gt;
&lt;Event logger=&quot;com.foo.Bar&quot; timestamp=&quot;1373436580419&quot; level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
&lt;Message&gt;&lt;![CDATA[This is a log message 1]]&gt;&lt;/Message&gt;
&lt;Marker parent=&quot;Parent Marker&quot;&gt;&lt;Child Marker&gt;&lt;/Marker&gt;
&lt;/Event&gt;
&lt;Event logger=&quot;com.foo.Baz&quot; timestamp=&quot;1373436580420&quot; level=&quot;INFO&quot; thread=&quot;main&quot;&gt;
&lt;Message&gt;&lt;![CDATA[This is a log message 2]]&gt;&lt;/Message&gt;
&lt;Marker&gt;&lt;The Marker Name&gt;&lt;/Marker&gt;
&lt;/Event&gt;
&lt;/Events&gt;</pre></div>
<p>
If <tt>complete=&quot;false&quot;</tt>, the appender does not write the XML processing instruction and the root
element.
</p>
<p>
This approach enforces the independence of the XMLLayout and the appender where you embed it.
</p>
</div><div class="section"><h4>Marker<a name="Marker"></a></h4>
<p>Markers are represented by a <tt>Marker</tt> element within the <tt>Event</tt> element.
The <tt>Marker</tt> element appears only when a marker is used in the log message. The name of the marker's
parent will be provided in the <tt>parent</tt> attribute of the <tt>Marker</tt> element.
Only the leaf marker is included, not the full hierarchy.
</p>
</div><div class="section"><h4>Encoding<a name="Encoding"></a></h4>
<p>
Appenders using this layout should have their <tt>charset</tt> set to <tt>UTF-8</tt> or
<tt>UTF-16</tt>, otherwise events containing non ASCII characters could result in corrupted log files.
</p>
</div><div class="section"><h4>Pretty vs. compact XML<a name="Pretty_vs._compact_XML"></a></h4>
<p>
By default, the XML layout is not compact (a.k.a. not &quot;pretty&quot;) with <tt>compact=&quot;false&quot;</tt>, which
means the appender uses end-of-line characters and indents lines to format the XML. If
<tt>compact=&quot;true&quot;</tt>, then no end-of-line or indentation is used. Message content may contain,
of course, end-of-lines.
</p>
</div></div>
<a name="LocationInformation"></a>
<div class="section"><h3>Location Information<a name="Location_Information"></a></h3>
<p>
If one of the layouts is
configured with a location-related attribute like
HTML <a href="#HtmlLocationInfo">locationInfo</a>,
or one of the patterns
<a href="#PatternClass">%C or $class</a>,
<a href="#PatternFile">%F or %file</a>,
<a href="#PatternLocation">%l or %location</a>,
<a href="#PatternLine">%L or %line</a>,
<a href="#PatternMethod">%M or %method</a>,
Log4j will take a snapshot of the
stack, and walk the stack trace to find the location information.
</p>
<p>
This is an expensive operation: 1.3 - 5 times slower for
synchronous loggers. Synchronous loggers wait as
long as possible before they take this stack snapshot. If no
location is required, the snapshot will never be taken.
</p><p>
However,
asynchronous loggers need to make this decision before passing the
log message to another thread; the location information will be
lost after that point.
The performance impact of taking a stack trace snapshot is even
higher for asynchronous loggers: logging with location is
4 - 20 times slower than without location.
For this reason, asynchronous loggers and asynchronous
appenders do not include location information by default.
</p><p>
You can override the default behaviour in your logger
or asynchronous appender configuration
by specifying
<tt>includeLocation=&quot;true&quot;</tt>.
</p>
<p>
</p>
</div>
</div>
</td>
</tr>
</table>
</div>
<div class="footer">
<p>Copyright &copy; 1999-2014 <a class="external" href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.</p>
<p>Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, and the Apache Logging project logo are trademarks of The Apache Software Foundation.</p>
<p>Site powered by <a class="external" href="http://getbootstrap.com/">Twitter Bootstrap</a>. Icons from <a class="external" href="http://glyphicons.com/">Glyphicons Free</a>.</p>
</div>
</div>
</body>
</html>