Class HtmlLayout

    • Field Detail

      • DEFAULT_FONT_FAMILY

        public static final java.lang.String DEFAULT_FONT_FAMILY
        Default font family: "arial,sans-serif".
        See Also:
        Constant Field Values
      • REGEXP

        private static final java.lang.String REGEXP
      • DEFAULT_CONTENT_TYPE

        private static final java.lang.String DEFAULT_CONTENT_TYPE
        See Also:
        Constant Field Values
      • jvmStartTime

        private final long jvmStartTime
      • locationInfo

        private final boolean locationInfo
      • title

        private final java.lang.String title
      • contentType

        private final java.lang.String contentType
      • font

        private final java.lang.String font
      • fontSize

        private final java.lang.String fontSize
      • headerSize

        private final java.lang.String headerSize
    • Constructor Detail

      • HtmlLayout

        private HtmlLayout​(boolean locationInfo,
                           java.lang.String title,
                           java.lang.String contentType,
                           java.nio.charset.Charset charset,
                           java.lang.String font,
                           java.lang.String fontSize,
                           java.lang.String headerSize)
    • Method Detail

      • getTitle

        public java.lang.String getTitle()
        For testing purposes.
      • isLocationInfo

        public boolean isLocationInfo()
        For testing purposes.
      • addCharsetToContentType

        private java.lang.String addCharsetToContentType​(java.lang.String contentType)
      • toSerializable

        public java.lang.String toSerializable​(LogEvent event)
        Formats as a String.
        Parameters:
        event - The Logging Event.
        Returns:
        A String containing the LogEvent as HTML.
      • 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>
        Overrides:
        getContentType in class AbstractStringLayout
        Returns:
        The default content type for Strings.
      • appendThrowableAsHtml

        private void appendThrowableAsHtml​(java.lang.Throwable throwable,
                                           java.lang.StringBuilder sbuf)
      • appendLs

        private java.lang.StringBuilder appendLs​(java.lang.StringBuilder sbuilder,
                                                 java.lang.String s)
      • append

        private java.lang.StringBuilder append​(java.lang.StringBuilder sbuilder,
                                               java.lang.String s)
      • getHeader

        public byte[] getHeader()
        Returns appropriate HTML headers.
        Specified by:
        getHeader in interface Layout<java.lang.String>
        Overrides:
        getHeader in class AbstractStringLayout
        Returns:
        The header as a byte array.
      • getFooter

        public byte[] getFooter()
        Returns the appropriate HTML footers.
        Specified by:
        getFooter in interface Layout<java.lang.String>
        Overrides:
        getFooter in class AbstractStringLayout
        Returns:
        the footer as a byte array.
      • createLayout

        @PluginFactory
        public static HtmlLayout createLayout​(@PluginAttribute("locationInfo")
                                              boolean locationInfo,
                                              @PluginAttribute(value="title",defaultString="Log4j Log Messages")
                                              java.lang.String title,
                                              @PluginAttribute("contentType")
                                              java.lang.String contentType,
                                              @PluginAttribute(value="charset",defaultString="UTF-8")
                                              java.nio.charset.Charset charset,
                                              @PluginAttribute("fontSize")
                                              java.lang.String fontSize,
                                              @PluginAttribute(value="fontName",defaultString="arial,sans-serif")
                                              java.lang.String font)
        Creates an HTML Layout.
        Parameters:
        locationInfo - If "true", location information will be included. The default is false.
        title - The title to include in the file header. If none is specified the default title will be used.
        contentType - The content type. Defaults to "text/html".
        charset - The character set to use. If not specified, the default will be used.
        fontSize - The font size of the text.
        font - The font to use for the text.
        Returns:
        An HTML Layout.
      • createDefaultLayout

        public static HtmlLayout createDefaultLayout()
        Creates an HTML Layout using the default settings.
        Returns:
        an HTML Layout.