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.AbstractJacksonLayout
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 AbstractJacksonLayout
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
Nested ClassesModifier and TypeClassDescriptionstatic class
YamlLayout.Builder<B extends YamlLayout.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
FieldsModifier and TypeFieldDescription(package private) static final String
private static final String
private static final String
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
ConstructorsModifierConstructorDescriptionprivate
YamlLayout
(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String endOfLine, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields) protected
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 AbstractJacksonLayout
Creates a YAML Layout using the default settings.static 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>>
BMethods 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 Details
-
DEFAULT_FOOTER
- See Also:
-
DEFAULT_HEADER
- See Also:
-
CONTENT_TYPE
- See Also:
-
-
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 -
YamlLayout
private YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String endOfLine, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields)
-
-
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 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 header 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
Creates a YAML Layout using the default settings. Useful for testing.- Returns:
- A YAML Layout.
-
newBuilder()
instead