@Plugin(name="XmlLayout", category="Core", elementType="layout", printObject=true) public final class XmlLayout extends AbstractStringLayout
event
elements as defined in the log4j.dtd.
If you configure complete="true"
, the appender outputs a well-formed XML document where the default namespace
is the log4j namespace . By default, with complete="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.
Appenders using this layout should have their charset
set to UTF-8
or UTF-16
, otherwise
events containing non-ASCII characters could result in corrupted log files.
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. If compact="true"
, then no
end-of-line or indentation is used. Message content may contain, of course, end-of-lines.
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.
Modifier and Type | Class and Description |
---|---|
static class |
AbstractJacksonLayout.LogEventWithAdditionalFields |
protected static class |
AbstractJacksonLayout.ResolvableKeyValuePair |
static class |
XmlLayout.Builder<B extends XmlLayout.Builder<B>> |
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
Modifier and Type | Field and Description |
---|---|
protected AbstractJacksonLayout.ResolvableKeyValuePair[] |
additionalFields |
protected boolean |
compact |
protected static String |
COMPACT_EOL |
protected boolean |
complete |
protected static String |
DEFAULT_EOL |
protected String |
eol |
protected boolean |
includeNullDelimiter |
protected com.fasterxml.jackson.databind.ObjectWriter |
objectWriter |
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
configuration, eventCount, footer, header, LOGGER
ELEMENT_TYPE
Modifier | Constructor and Description |
---|---|
protected |
XmlLayout(boolean locationInfo,
boolean properties,
boolean complete,
boolean compact,
Charset charset,
boolean includeStacktrace)
Deprecated.
Use
newBuilder() instead |
Modifier and Type | Method and Description |
---|---|
static XmlLayout |
createDefaultLayout()
Creates an XML Layout using the default settings.
|
static XmlLayout |
createLayout(boolean locationInfo,
boolean properties,
boolean complete,
boolean compact,
Charset charset,
boolean includeStacktrace)
Deprecated.
Use
newBuilder() instead |
Map<String,String> |
getContentFormat()
Gets this XmlLayout's content format.
|
String |
getContentType()
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>> |
newBuilder() |
String |
toSerializable(LogEvent event)
Formats a
LogEvent . |
void |
toSerializable(LogEvent event,
Writer writer) |
protected static boolean |
valueNeedsLookup(String value) |
protected Object |
wrapLogEvent(LogEvent event) |
getBytes, getCharset, getFooterSerializer, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, requiresLocation, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
encode, getConfiguration, markEvent
protected static final String DEFAULT_EOL
protected static final String COMPACT_EOL
protected final String eol
protected final com.fasterxml.jackson.databind.ObjectWriter objectWriter
protected final boolean compact
protected final boolean complete
protected final boolean includeNullDelimiter
protected final AbstractJacksonLayout.ResolvableKeyValuePair[] additionalFields
@Deprecated protected XmlLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, Charset charset, boolean includeStacktrace)
newBuilder()
insteadpublic byte[] getHeader()
getHeader
in interface Layout<String>
getHeader
in class AbstractStringLayout
public byte[] getFooter()
getFooter
in interface Layout<String>
getFooter
in class AbstractStringLayout
public Map<String,String> getContentFormat()
getContentFormat
in interface Layout<String>
getContentFormat
in class AbstractLayout<String>
public String getContentType()
Layout
getContentType
in interface Layout<String>
getContentType
in class AbstractStringLayout
@Deprecated public static XmlLayout createLayout(boolean locationInfo, boolean properties, boolean complete, boolean compact, Charset charset, boolean includeStacktrace)
newBuilder()
insteadlocationInfo
- 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, if null
, uses "UTF-8".includeStacktrace
- If "true", includes the stacktrace of any Throwable in the generated XML, defaults to "true".@PluginBuilderFactory public static <B extends XmlLayout.Builder<B>> B newBuilder()
public static XmlLayout createDefaultLayout()
protected static boolean valueNeedsLookup(String value)
public String toSerializable(LogEvent event)
LogEvent
.event
- The LogEvent.public void toSerializable(LogEvent event, Writer writer) throws com.fasterxml.jackson.core.JsonGenerationException, com.fasterxml.jackson.databind.JsonMappingException, IOException
com.fasterxml.jackson.core.JsonGenerationException
com.fasterxml.jackson.databind.JsonMappingException
IOException
Copyright © 1999-2023 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.