Layout<String>
, Encoder<String>
, StringLayout
@Plugin(name="YamlLayout", category="Core", elementType="layout", printObject=true) public final class YamlLayout extends AbstractStringLayout
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.
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.
Modifier and Type | Class | Description |
---|---|---|
static class |
YamlLayout.Builder<B extends YamlLayout.Builder<B>> |
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
Modifier and Type | Field | Description |
---|---|---|
protected org.apache.logging.log4j.core.layout.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 |
configuration, eventCount, footer, header, LOGGER
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
ELEMENT_TYPE
Modifier | Constructor | Description |
---|---|---|
protected |
YamlLayout(Configuration config,
boolean locationInfo,
boolean properties,
boolean complete,
boolean compact,
boolean eventEol,
String headerPattern,
String footerPattern,
Charset charset,
boolean includeStacktrace) |
Deprecated.
Use
newBuilder() instead |
Modifier and Type | Method | Description |
---|---|---|
static org.apache.logging.log4j.core.layout.AbstractJacksonLayout |
createDefaultLayout() |
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.
Use
newBuilder() instead |
Map<String,String> |
getContentFormat() |
Returns a description of the content format.
|
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>> |
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) |
encode, getConfiguration, markEvent
getBytes, getCharset, getFooterSerializer, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
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 org.apache.logging.log4j.core.layout.AbstractJacksonLayout.ResolvableKeyValuePair[] additionalFields
@Deprecated protected YamlLayout(Configuration config, boolean locationInfo, boolean properties, boolean complete, boolean compact, boolean eventEol, String headerPattern, String footerPattern, 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()
Layout
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 org.apache.logging.log4j.core.layout.AbstractJacksonLayout createLayout(Configuration config, boolean locationInfo, boolean properties, String headerPattern, String footerPattern, Charset charset, boolean includeStacktrace)
newBuilder()
insteadconfig
- 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, if null
, uses "UTF-8".includeStacktrace
- If "true", includes the stacktrace of any Throwable in the generated YAML, defaults to "true".@PluginBuilderFactory public static <B extends YamlLayout.Builder<B>> B newBuilder()
public static org.apache.logging.log4j.core.layout.AbstractJacksonLayout 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-2018. 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.