Class AbstractLayout<T extends Serializable>

    • 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)
        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
        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

      • getContentFormat

        public Map<String,​String> getContentFormat()
        Description copied from interface: Layout
        Returns a description of the content format.
        Specified by:
        getContentFormat in interface Layout<T extends 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.
        Specified by:
        getFooter in interface Layout<T extends Serializable>
        Returns:
        A byte array containing the footer.
      • getHeader

        public byte[] getHeader()
        Returns the header, if one is available.
        Specified by:
        getHeader in interface Layout<T extends Serializable>
        Returns:
        A byte array containing the header.
      • 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, AbstractStringLayout provides 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:
        encode in interface Encoder<T extends Serializable>
        Parameters:
        event - the LogEvent to encode.
        destination - holds the ByteBuffer to write into.
        See Also:
        AbstractStringLayout.getStringBuilder(), AbstractStringLayout.getStringBuilderEncoder()