Layout<String>
, Encoder<LogEvent>
, StringLayout
AbstractCsvLayout
, GelfLayout
, HtmlLayout
, JsonLayout
, Log4j1XmlLayout
, PatternLayout
, Rfc5424Layout
, SyslogLayout
, XmlLayout
, YamlLayout
public abstract class AbstractStringLayout extends AbstractLayout<String> implements StringLayout
Since 2.4.1, this class has custom logic to convert ISO-8859-1 or US-ASCII Strings to byte[] arrays to improve performance: all characters are simply cast to bytes.
Modifier and Type | Class | Description |
---|---|---|
static class |
AbstractStringLayout.Builder<B extends AbstractStringLayout.Builder<B>> |
|
static interface |
AbstractStringLayout.Serializer |
|
static interface |
AbstractStringLayout.Serializer2 |
Variation of
AbstractStringLayout.Serializer that avoids allocating temporary objects. |
Modifier and Type | Field | Description |
---|---|---|
protected static int |
DEFAULT_STRING_BUILDER_SIZE |
Default length for new StringBuilder instances: 1024 .
|
protected static int |
MAX_STRING_BUILDER_SIZE |
configuration, eventCount, footer, header, LOGGER
ELEMENT_TYPE
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractStringLayout(Charset charset) |
|
protected |
AbstractStringLayout(Charset aCharset,
byte[] header,
byte[] footer) |
Builds a new layout.
|
protected |
AbstractStringLayout(Configuration config,
Charset aCharset,
AbstractStringLayout.Serializer headerSerializer,
AbstractStringLayout.Serializer footerSerializer) |
Builds a new layout.
|
Modifier and Type | Method | Description |
---|---|---|
protected byte[] |
getBytes(String s) |
|
Charset |
getCharset() |
Gets the Charset this layout uses to encode Strings into bytes.
|
String |
getContentType() |
Returns the content type output by this layout.
|
byte[] |
getFooter() |
Returns the footer, if one is available.
|
AbstractStringLayout.Serializer |
getFooterSerializer() |
|
byte[] |
getHeader() |
Returns the header, if one is available.
|
AbstractStringLayout.Serializer |
getHeaderSerializer() |
|
protected static StringBuilder |
getStringBuilder() |
Returns a
StringBuilder that this Layout implementation can use to write the formatted log event to. |
protected Encoder<StringBuilder> |
getStringBuilderEncoder() |
Returns a
Encoder<StringBuilder> that this Layout implementation can use for encoding log events. |
protected byte[] |
serializeToBytes(AbstractStringLayout.Serializer serializer,
byte[] defaultValue) |
|
protected String |
serializeToString(AbstractStringLayout.Serializer serializer) |
|
byte[] |
toByteArray(LogEvent event) |
Formats the Log Event as a byte array.
|
protected static void |
trimToMaxSize(StringBuilder stringBuilder) |
encode, getConfiguration, getContentFormat, markEvent
getContentFormat, toSerializable
protected static final int DEFAULT_STRING_BUILDER_SIZE
protected static final int MAX_STRING_BUILDER_SIZE
protected AbstractStringLayout(Charset charset)
protected AbstractStringLayout(Charset aCharset, byte[] header, byte[] footer)
aCharset
- the charset used to encode the header bytes, footer bytes and anything else that needs to be
converted from strings to bytes.header
- the header bytesfooter
- the footer bytesprotected AbstractStringLayout(Configuration config, Charset aCharset, AbstractStringLayout.Serializer headerSerializer, AbstractStringLayout.Serializer footerSerializer)
config
- the configurationaCharset
- the charset used to encode the header bytes, footer bytes and anything else that needs to be
converted from strings to bytes.headerSerializer
- the header bytes serializerfooterSerializer
- the footer bytes serializerprotected static StringBuilder getStringBuilder()
StringBuilder
that this Layout implementation can use to write the formatted log event to.StringBuilder
protected static void trimToMaxSize(StringBuilder stringBuilder)
protected byte[] getBytes(String s)
public Charset getCharset()
StringLayout
getCharset
in interface StringLayout
public String getContentType()
Layout
getContentType
in interface Layout<String>
public byte[] getFooter()
public AbstractStringLayout.Serializer getFooterSerializer()
public byte[] getHeader()
public AbstractStringLayout.Serializer getHeaderSerializer()
protected Encoder<StringBuilder> getStringBuilderEncoder()
Encoder<StringBuilder>
that this Layout implementation can use for encoding log events.Encoder<StringBuilder>
protected byte[] serializeToBytes(AbstractStringLayout.Serializer serializer, byte[] defaultValue)
protected String serializeToString(AbstractStringLayout.Serializer serializer)
public byte[] toByteArray(LogEvent event)
toByteArray
in interface Layout<String>
event
- The Log Event.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.