Class AbstractStringLayout

    • Field Detail

      • DEFAULT_STRING_BUILDER_SIZE

        protected static final int DEFAULT_STRING_BUILDER_SIZE
        Default length for new StringBuilder instances: 1024 .
        See Also:
        Constant Field Values
      • MAX_STRING_BUILDER_SIZE

        protected static final int MAX_STRING_BUILDER_SIZE
      • threadLocal

        private static final java.lang.ThreadLocal<java.lang.StringBuilder> threadLocal
      • textEncoder

        private Encoder<java.lang.StringBuilder> textEncoder
      • charset

        private transient java.nio.charset.Charset charset
        The charset for the formatted message.
      • charsetName

        private final java.lang.String charsetName
      • useCustomEncoding

        private final boolean useCustomEncoding
    • Constructor Detail

      • AbstractStringLayout

        protected AbstractStringLayout​(java.nio.charset.Charset charset)
      • AbstractStringLayout

        protected AbstractStringLayout​(java.nio.charset.Charset aCharset,
                                       byte[] header,
                                       byte[] footer)
        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 bytes
        footer - the footer bytes
      • AbstractStringLayout

        protected AbstractStringLayout​(Configuration config,
                                       java.nio.charset.Charset aCharset,
                                       AbstractStringLayout.Serializer headerSerializer,
                                       AbstractStringLayout.Serializer footerSerializer)
        Builds a new layout.
        Parameters:
        config - the configuration
        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 serializer
        footerSerializer - the footer bytes serializer
    • Method Detail

      • getStringBuilder

        protected static java.lang.StringBuilder getStringBuilder()
        Returns a StringBuilder that this Layout implementation can use to write the formatted log event to.
        Returns:
        a StringBuilder
      • isPreJava8

        private static boolean isPreJava8()
      • size

        private static int size​(java.lang.String property,
                                int defaultValue)
      • trimToMaxSize

        protected static void trimToMaxSize​(java.lang.StringBuilder stringBuilder)
      • getBytes

        protected byte[] getBytes​(java.lang.String s)
      • getCharset

        public java.nio.charset.Charset getCharset()
        Description copied from interface: StringLayout
        Gets the Charset this layout uses to encode Strings into bytes.
        Specified by:
        getCharset in interface StringLayout
        Returns:
        the Charset this layout uses to encode Strings into bytes.
      • getContentType

        public java.lang.String getContentType()
        Description copied from interface: Layout
        Returns the content type output by this layout. The base class returns "text/plain".
        Specified by:
        getContentType in interface Layout<java.lang.String>
        Returns:
        The default content type for Strings.
      • getFooter

        public byte[] getFooter()
        Returns the footer, if one is available.
        Specified by:
        getFooter in interface Layout<java.lang.String>
        Overrides:
        getFooter in class AbstractLayout<java.lang.String>
        Returns:
        A byte array containing the footer.
      • getHeader

        public byte[] getHeader()
        Returns the header, if one is available.
        Specified by:
        getHeader in interface Layout<java.lang.String>
        Overrides:
        getHeader in class AbstractLayout<java.lang.String>
        Returns:
        A byte array containing the header.
      • getStringBuilderEncoder

        protected Encoder<java.lang.StringBuilder> getStringBuilderEncoder()
        Returns a Encoder<StringBuilder> that this Layout implementation can use for encoding log events.
        Returns:
        a Encoder<StringBuilder>
      • toByteArray

        public byte[] toByteArray​(LogEvent event)
        Formats the Log Event as a byte array.
        Specified by:
        toByteArray in interface Layout<java.lang.String>
        Parameters:
        event - The Log Event.
        Returns:
        The formatted event as a byte array.