Class YamlLayout
- 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.YamlLayout
-
- All Implemented Interfaces:
LocationAware
,Layout<java.lang.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 toUTF-8
orUTF-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>
insertsfoo: "bar"
directly into YAML output. Supports Lookup expressions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static 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
Fields Modifier and Type Field Description (package private) static java.lang.String
CONTENT_TYPE
private static java.lang.String
DEFAULT_FOOTER
private static java.lang.String
DEFAULT_HEADER
-
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 private
YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, java.lang.String endOfLine, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.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, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.Charset charset, boolean includeStacktrace)
Deprecated.UsenewBuilder()
instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static AbstractJacksonLayout
createDefaultLayout()
Creates a YAML Layout using the default settings.static AbstractJacksonLayout
createLayout(Configuration config, boolean locationInfo, boolean properties, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.Charset charset, boolean includeStacktrace)
Deprecated.UsenewBuilder()
insteadjava.util.Map<java.lang.String,java.lang.String>
getContentFormat()
Returns a description of the content format.java.lang.String
getContentType()
Returns the content type output by this layout.byte[]
getFooter()
Returns appropriate YAML footer.byte[]
getHeader()
Returns appropriate YAML header.static <B extends YamlLayout.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
-
DEFAULT_FOOTER
private static final java.lang.String DEFAULT_FOOTER
- See Also:
- Constant Field Values
-
DEFAULT_HEADER
private static final java.lang.String DEFAULT_HEADER
- See Also:
- Constant Field Values
-
CONTENT_TYPE
static final java.lang.String CONTENT_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
YamlLayout
@Deprecated protected YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.Charset charset, boolean includeStacktrace)
Deprecated.UsenewBuilder()
instead
-
YamlLayout
private YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, java.lang.String endOfLine, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.Charset charset, boolean includeStacktrace, boolean stacktraceAsString, boolean includeNullDelimiter, boolean includeTimeMillis, KeyValuePair[] additionalFields)
-
-
Method Detail
-
getHeader
public byte[] getHeader()
Returns appropriate YAML header.- Specified by:
getHeader
in interfaceLayout<java.lang.String>
- Overrides:
getHeader
in classAbstractStringLayout
- Returns:
- a byte array containing the header, opening the YAML array.
-
getFooter
public byte[] getFooter()
Returns appropriate YAML footer.- Specified by:
getFooter
in interfaceLayout<java.lang.String>
- Overrides:
getFooter
in classAbstractStringLayout
- Returns:
- a byte array containing the footer, closing the YAML array.
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Description copied from interface:Layout
Returns a description of the content format.- Specified by:
getContentFormat
in interfaceLayout<java.lang.String>
- Overrides:
getContentFormat
in classAbstractLayout<java.lang.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
public java.lang.String 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<java.lang.String>
- Overrides:
getContentType
in classAbstractStringLayout
- Returns:
- The content type.
-
createLayout
@Deprecated public static AbstractJacksonLayout createLayout(Configuration config, boolean locationInfo, boolean properties, java.lang.String headerPattern, java.lang.String footerPattern, java.nio.charset.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
@PluginBuilderFactory public static <B extends YamlLayout.Builder<B>> B newBuilder()
-
createDefaultLayout
public static AbstractJacksonLayout createDefaultLayout()
Creates a YAML Layout using the default settings. Useful for testing.- Returns:
- A YAML Layout.
-
-