Class YamlLayout
java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
org.apache.logging.log4j.core.layout.YamlLayout
- All Implemented Interfaces:
LocationAware
,Layout<String>
,Encoder<LogEvent>
,StringLayout
@Plugin(name="YamlLayout",
category="Core",
elementType="layout",
printObject=true)
public final class YamlLayout
extends AbstractStringLayout
Appends a series of YAML events as strings serialized as bytes.
Encoding
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.
Additional Fields
This property allows addition of custom fields into generated JSON.
<YamlLayout><KeyValuePair key="foo" value="bar"/></YamlLayout>
inserts foo: "bar"
directly
into YAML output. Supports Lookup expressions.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
YamlLayout.Builder<B extends YamlLayout.Builder<B>>
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
Field Summary
Modifier and TypeFieldDescriptionprotected final org.apache.logging.log4j.core.layout.AbstractJacksonLayout.ResolvableKeyValuePair[]
protected final boolean
protected static final String
protected final boolean
protected static final String
protected final String
protected final boolean
protected final com.fasterxml.jackson.databind.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
ModifierConstructorDescriptionprotected
YamlLayout
(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.logging.log4j.core.layout.AbstractJacksonLayout
Creates a YAML Layout using the default settings.static org.apache.logging.log4j.core.layout.AbstractJacksonLayout
createLayout
(Configuration config, boolean locationInfo, boolean properties, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace) Deprecated.UsenewBuilder()
insteadReturns a description of the content format.Returns the content type output by this layout.byte[]
Returns appropriate YAML footer.byte[]
Returns appropriate YAML header.static <B extends YamlLayout.Builder<B>>
BtoSerializable
(LogEvent event) Formats aLogEvent
.void
toSerializable
(LogEvent event, Writer writer) protected static boolean
valueNeedsLookup
(String value) protected Object
wrapLogEvent
(LogEvent event) 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 Details
-
DEFAULT_EOL
- See Also:
-
COMPACT_EOL
- See Also:
-
eol
-
objectWriter
protected final com.fasterxml.jackson.databind.ObjectWriter objectWriter -
compact
protected final boolean compact -
complete
protected final boolean complete -
includeNullDelimiter
protected final boolean includeNullDelimiter -
additionalFields
protected final org.apache.logging.log4j.core.layout.AbstractJacksonLayout.ResolvableKeyValuePair[] additionalFields
-
-
Constructor Details
-
YamlLayout
@Deprecated protected YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace) Deprecated.UsenewBuilder()
instead
-
-
Method Details
-
getHeader
public byte[] getHeader()Returns appropriate YAML header.- Specified by:
getHeader
in interfaceLayout<String>
- Overrides:
getHeader
in classAbstractStringLayout
- Returns:
- a byte array containing the header, opening the YAML array.
-
getContentFormat
Description copied from interface:Layout
Returns a description of the content format.- Specified by:
getContentFormat
in interfaceLayout<String>
- Overrides:
getContentFormat
in classAbstractLayout<String>
- Returns:
- a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.
-
getContentType
Description copied from interface:Layout
Returns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentType
in interfaceLayout<String>
- Overrides:
getContentType
in classAbstractStringLayout
- Returns:
- The content type.
-
createLayout
@Deprecated public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout createLayout(Configuration config, boolean locationInfo, boolean properties, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace) Deprecated.UsenewBuilder()
insteadCreates a YAML Layout.- Parameters:
config
- The plugin configuration.locationInfo
- If "true", includes the location information in the generated YAML.properties
- If "true", includes the thread context map in the generated YAML.headerPattern
- The header pattern, defaults to""
if null.footerPattern
- The footer pattern, defaults to""
if null.charset
- The character set to use, ifnull
, uses "UTF-8".includeStacktrace
- If "true", includes the stacktrace of any Throwable in the generated YAML, defaults to "true".- Returns:
- A YAML Layout.
-
newBuilder
-
createDefaultLayout
public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout createDefaultLayout()Creates a YAML Layout using the default settings. Useful for testing.- Returns:
- A YAML Layout.
-
valueNeedsLookup
-
toSerializable
Formats aLogEvent
.- Parameters:
event
- The LogEvent.- Returns:
- The XML representation of the LogEvent.
-
wrapLogEvent
-
toSerializable
public void toSerializable(LogEvent event, Writer writer) throws com.fasterxml.jackson.core.JsonGenerationException, com.fasterxml.jackson.databind.JsonMappingException, IOException - Throws:
com.fasterxml.jackson.core.JsonGenerationException
com.fasterxml.jackson.databind.JsonMappingException
IOException
-
newBuilder()
instead