Class AbstractLayout<T extends java.io.Serializable>
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<T>
-
- Type Parameters:
T- The Class that the Layout will format the LogEvent into.
- Direct Known Subclasses:
AbstractStringLayout,MessageLayout,SerializedLayout
public abstract class AbstractLayout<T extends java.io.Serializable> extends java.lang.Object implements Layout<T>
Abstract base class for Layouts.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractLayout.Builder<B extends AbstractLayout.Builder<B>>Subclasses can extend this abstract Builder.
-
Field Summary
Fields Modifier and Type Field Description protected ConfigurationconfigurationThe current Configuration.protected longeventCountThe number of events successfully processed by this layout.protected byte[]footerThe footer to add when the stream is closed.protected byte[]headerThe header to include when the stream is opened.protected static LoggerLOGGERAllow subclasses access to the status logger without creating another instance.-
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
-
Constructor Summary
Constructors Constructor Description AbstractLayout(byte[] header, byte[] footer)Deprecated.AbstractLayout(Configuration configuration, byte[] header, byte[] footer)Constructs a layout with an optional header and footer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidencode(LogEvent event, ByteBufferDestination destination)Encodes the specified source LogEvent to some binary representation and writes the result to the specified destination.ConfigurationgetConfiguration()java.util.Map<java.lang.String,java.lang.String>getContentFormat()Returns a description of the content format.byte[]getFooter()Returns the footer, if one is available.byte[]getHeader()Returns the header, if one is available.protected voidmarkEvent()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.logging.log4j.core.Layout
getContentType, toByteArray, toSerializable
-
-
-
-
Field Detail
-
LOGGER
protected static final Logger LOGGER
Allow subclasses access to the status logger without creating another instance.
-
configuration
protected final Configuration configuration
The current Configuration.
-
eventCount
protected long eventCount
The number of events successfully processed by this layout.
-
footer
protected final byte[] footer
The footer to add when the stream is closed. May be null.
-
header
protected final byte[] header
The header to include when the stream is opened. May be null.
-
-
Constructor Detail
-
AbstractLayout
@Deprecated public AbstractLayout(byte[] header, byte[] footer)Deprecated.Constructs a layout with an optional header and footer.- Parameters:
header- The header to include when the stream is opened. May be null.footer- The footer to add when the stream is closed. May be null.
-
AbstractLayout
public AbstractLayout(Configuration configuration, byte[] header, byte[] footer)
Constructs a layout with an optional header and footer.- Parameters:
configuration- The configuration. May be null.header- The header to include when the stream is opened. May be null.footer- The footer to add when the stream is closed. May be null.
-
-
Method Detail
-
getConfiguration
public Configuration getConfiguration()
-
getContentFormat
public java.util.Map<java.lang.String,java.lang.String> getContentFormat()
Description copied from interface:LayoutReturns a description of the content format.- Specified by:
getContentFormatin interfaceLayout<T extends java.io.Serializable>- Returns:
- a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.
-
getFooter
public byte[] getFooter()
Returns the footer, if one is available.
-
getHeader
public byte[] getHeader()
Returns the header, if one is available.
-
markEvent
protected void markEvent()
-
encode
public void encode(LogEvent event, ByteBufferDestination destination)
Encodes the specified source LogEvent to some binary representation and writes the result to the specified destination.The default implementation of this method delegates to the
Layout.toByteArray(LogEvent)method which allocates temporary objects.Subclasses can override this method to provide a garbage-free implementation. For text-based layouts,
AbstractStringLayoutprovides various convenience methods to help with this:@Plugin(name = "MyLayout", category = Node.CATEGORY, elementType = Layout.ELEMENT_TYPE, printObject = true) public final class MyLayout extends AbstractStringLayout {- Specified by:
encodein interfaceEncoder<T extends java.io.Serializable>- Parameters:
event- the LogEvent to encode.destination- holds the ByteBuffer to write into.- See Also:
AbstractStringLayout.getStringBuilder(),AbstractStringLayout.getStringBuilderEncoder()
-
-