Class AbstractStringLayout
java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
- All Implemented Interfaces:
LocationAware,Layout<String>,Encoder<LogEvent>,StringLayout
- Direct Known Subclasses:
AbstractCsvLayout,GelfLayout,HtmlLayout,JsonLayout,PatternLayout,Rfc5424Layout,SyslogLayout,XmlLayout,YamlLayout
public abstract class AbstractStringLayout
extends AbstractLayout<String>
implements StringLayout, LocationAware
Abstract base class for Layouts that result in a String.
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfacestatic interfaceVariation ofAbstractStringLayout.Serializerthat avoids allocating temporary objects. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intDefault length for new StringBuilder instances: 1024 .protected static final intFields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGERFields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractStringLayout(Charset charset) protectedAbstractStringLayout(Charset aCharset, byte[] header, byte[] footer) Builds a new layout.protectedAbstractStringLayout(Configuration config, Charset aCharset, AbstractStringLayout.Serializer headerSerializer, AbstractStringLayout.Serializer footerSerializer) Builds a new layout. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]Gets the Charset this layout uses to encode Strings into bytes.Returns the content type output by this layout.byte[]Returns the footer, if one is available.byte[]Returns the header, if one is available.protected static StringBuilderReturns aStringBuilderthat this Layout implementation can use to write the formatted log event to.protected Encoder<StringBuilder>Returns aEncoder<StringBuilder>that this Layout implementation can use for encoding log events.booleanprotected byte[]serializeToBytes(AbstractStringLayout.Serializer serializer, byte[] defaultValue) protected StringserializeToString(AbstractStringLayout.Serializer serializer) byte[]toByteArray(LogEvent event) Formats the Log Event as a byte array.protected static voidtrimToMaxSize(StringBuilder stringBuilder) Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, getContentFormat, markEventMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.core.Layout
getContentFormat, toSerializable
-
Field Details
-
DEFAULT_STRING_BUILDER_SIZE
protected static final int DEFAULT_STRING_BUILDER_SIZEDefault length for new StringBuilder instances: 1024 .- See Also:
-
MAX_STRING_BUILDER_SIZE
protected static final int MAX_STRING_BUILDER_SIZE
-
-
Constructor Details
-
AbstractStringLayout
-
AbstractStringLayout
Builds a new layout.- Parameters:
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 bytes
-
AbstractStringLayout
protected AbstractStringLayout(Configuration config, Charset aCharset, AbstractStringLayout.Serializer headerSerializer, AbstractStringLayout.Serializer footerSerializer) Builds a new layout.- Parameters:
config- the configuration. May be null.aCharset- 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 serializer
-
-
Method Details
-
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocationin interfaceLocationAware
-
getStringBuilder
Returns aStringBuilderthat this Layout implementation can use to write the formatted log event to.- Returns:
- a
StringBuilder
-
trimToMaxSize
-
getBytes
-
getCharset
Description copied from interface:StringLayoutGets the Charset this layout uses to encode Strings into bytes.- Specified by:
getCharsetin interfaceStringLayout- Returns:
- the Charset this layout uses to encode Strings into bytes.
-
getContentType
Description copied from interface:LayoutReturns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentTypein interfaceLayout<String>- Returns:
- The default content type for Strings.
-
getHeader
public byte[] getHeader()Returns the header, if one is available. -
getHeaderSerializer
-
getStringBuilderEncoder
Returns aEncoder<StringBuilder>that this Layout implementation can use for encoding log events.- Returns:
- a
Encoder<StringBuilder>
-
serializeToBytes
-
serializeToString
-
toByteArray
Formats the Log Event as a byte array.- Specified by:
toByteArrayin interfaceLayout<String>- Parameters:
event- The Log Event.- Returns:
- The formatted event as a byte array.
-