Class XmlLayout
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
- org.apache.logging.log4j.core.layout.AbstractStringLayout
-
- org.apache.logging.log4j.core.layout.AbstractJacksonLayout
-
- org.apache.logging.log4j.core.layout.XmlLayout
-
- All Implemented Interfaces:
LocationAware,Layout<java.lang.String>,Encoder<LogEvent>,StringLayout
@Plugin(name="XmlLayout", category="Core", elementType="layout", printObject=true) public final class XmlLayout extends AbstractJacksonLayout
Appends a series ofeventelements as defined in the log4j.dtd.Complete well-formed XML vs. fragment XML
If you configure
complete="true", the appender outputs a well-formed XML document where the default namespace is the log4j namespace "http://logging.apache.org/log4j/2.0/events". By default, withcomplete="false", you should include the output as an external entity in a separate file to form a well-formed XML document.If
complete="false", the appender does not write the XML processing instruction and the root element.Encoding
Appenders using this layout should have their
charsetset toUTF-8orUTF-16, otherwise events containing non-ASCII characters could result in corrupted log files.Pretty vs. compact XML
By default, the XML layout is not compact (compact = not "pretty") with
compact="false", which means the appender uses end-of-line characters and indents lines to format the XML. Ifcompact="true", then no end-of-line or indentation is used. Message content may contain, of course, end-of-lines.Additional Fields
This property allows addition of custom fields into generated JSON.
<XmlLayout><KeyValuePair key="foo" value="bar"/></XmlLayout>inserts<foo>bar</foo>directly into XML output. Supports Lookup expressions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classXmlLayout.Builder<B extends XmlLayout.Builder<B>>-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractJacksonLayout
AbstractJacksonLayout.LogEventWithAdditionalFields, AbstractJacksonLayout.ResolvableKeyValuePair
-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringROOT_TAG-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractJacksonLayout
additionalFields, compact, COMPACT_EOL, complete, DEFAULT_EOL, eol, includeNullDelimiter, objectWriter
-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedXmlLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, java.nio.charset.Charset charset, boolean includeStacktrace)Deprecated.UsenewBuilder()insteadprivateXmlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, java.lang.String endOfLine, java.nio.charset.Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static XmlLayoutcreateDefaultLayout()Creates an XML Layout using the default settings.static XmlLayoutcreateLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, java.nio.charset.Charset charset, boolean includeStacktrace)Deprecated.UsenewBuilder()insteadjava.util.Map<java.lang.String,java.lang.String>getContentFormat()Gets this XmlLayout's content format.java.lang.StringgetContentType()Returns the content type output by this layout.byte[]getFooter()Returns appropriate XML footer.byte[]getHeader()Returns appropriate XML headers.static <B extends XmlLayout.Builder<B>>
BnewBuilder()-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractJacksonLayout
toSerializable, toSerializable, valueNeedsLookup, wrapLogEvent
-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getFooterSerializer, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, markEvent
-
-
-
-
Field Detail
-
ROOT_TAG
private static final java.lang.String ROOT_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XmlLayout
@Deprecated protected XmlLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, java.nio.charset.Charset charset, boolean includeStacktrace)Deprecated.UsenewBuilder()instead
-
XmlLayout
private XmlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, java.lang.String endOfLine, java.nio.charset.Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields)
-
-
Method Detail
-
getHeader
public byte[] getHeader()
Returns appropriate XML headers.- XML processing instruction
- XML root element
- Specified by:
getHeaderin interfaceLayout<java.lang.String>- Overrides:
getHeaderin classAbstractStringLayout- Returns:
- a byte array containing the header.
-
getFooter
public byte[] getFooter()
Returns appropriate XML footer.- Specified by:
getFooterin interfaceLayout<java.lang.String>- Overrides:
getFooterin classAbstractStringLayout- Returns:
- a byte array containing the footer, closing the XML root element.
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Gets this XmlLayout's content format. Specified by:- Key: "dtd" Value: "log4j-events.dtd"
- Key: "version" Value: "2.0"
- Specified by:
getContentFormatin interfaceLayout<java.lang.String>- Overrides:
getContentFormatin classAbstractLayout<java.lang.String>- Returns:
- Map of content format keys supporting XmlLayout
-
getContentType
public java.lang.String getContentType()
Description copied from interface:LayoutReturns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentTypein interfaceLayout<java.lang.String>- Overrides:
getContentTypein classAbstractStringLayout- Returns:
- The content type.
-
createLayout
@Deprecated public static XmlLayout createLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, java.nio.charset.Charset charset, boolean includeStacktrace)
Deprecated.UsenewBuilder()insteadCreates an XML Layout.- Parameters:
locationInfo- If "true", includes the location information in the generated XML.properties- If "true", includes the thread context map in the generated XML.complete- If "true", includes the XML header and footer, defaults to "false".compact- If "true", does not use end-of-lines and indentation, defaults to "false".charset- The character set to use, ifnull, uses "UTF-8".includeStacktrace- If "true", includes the stacktrace of any Throwable in the generated XML, defaults to "true".- Returns:
- An XML Layout.
-
newBuilder
@PluginBuilderFactory public static <B extends XmlLayout.Builder<B>> B newBuilder()
-
createDefaultLayout
public static XmlLayout createDefaultLayout()
Creates an XML Layout using the default settings.- Returns:
- an XML Layout.
-
-