Class HtmlLayout
- java.lang.Object
-
- org.apache.logging.log4j.core.layout.AbstractLayout<java.lang.String>
-
- org.apache.logging.log4j.core.layout.AbstractStringLayout
-
- org.apache.logging.log4j.core.layout.HtmlLayout
-
- All Implemented Interfaces:
LocationAware,Layout<java.lang.String>,Encoder<LogEvent>,StringLayout
@Plugin(name="HtmlLayout", category="Core", elementType="layout", printObject=true) public final class HtmlLayout extends AbstractStringLayout
Outputs events as rows in an HTML table on an HTML page.Appenders using this layout should have their encoding set to UTF-8 or UTF-16, otherwise events containing non ASCII characters could result in corrupted log files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHtmlLayout.Builderstatic classHtmlLayout.FontSizePossible font sizes-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringDEFAULT_FONT_FAMILYDefault font family: "arial,sans-serif".-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZE
-
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGER
-
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static HtmlLayoutcreateDefaultLayout()Creates an HTML Layout using the default settings.static HtmlLayoutcreateLayout(boolean locationInfo, java.lang.String title, java.lang.String contentType, java.nio.charset.Charset charset, java.lang.String fontSize, java.lang.String font)Creates an HTML Layout.java.lang.StringgetContentType()Returns the content type output by this layout.byte[]getFooter()Returns the appropriate HTML footers.byte[]getHeader()Returns appropriate HTML headers.java.lang.StringgetTitle()For testing purposes.booleanisLocationInfo()For testing purposes.static HtmlLayout.BuildernewBuilder()booleanrequiresLocation()java.lang.StringtoSerializable(LogEvent event)Formats as a String.-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getFooterSerializer, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, serializeToBytes, serializeToString, toByteArray, trimToMaxSize
-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
encode, getConfiguration, getContentFormat, markEvent
-
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
getContentFormat
-
-
-
-
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
-
-
Method Detail
-
getTitle
public java.lang.String getTitle()
For testing purposes.
-
isLocationInfo
public boolean isLocationInfo()
For testing purposes.
-
requiresLocation
public boolean requiresLocation()
- Specified by:
requiresLocationin interfaceLocationAware- Overrides:
requiresLocationin classAbstractStringLayout
-
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:LayoutReturns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentTypein interfaceLayout<java.lang.String>- Overrides:
getContentTypein classAbstractStringLayout- Returns:
- The default content type for Strings.
-
getHeader
public byte[] getHeader()
Returns appropriate HTML headers.- Specified by:
getHeaderin interfaceLayout<java.lang.String>- Overrides:
getHeaderin classAbstractStringLayout- Returns:
- The header as a byte array.
-
getFooter
public byte[] getFooter()
Returns the appropriate HTML footers.- Specified by:
getFooterin interfaceLayout<java.lang.String>- Overrides:
getFooterin classAbstractStringLayout- 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.
-
newBuilder
@PluginBuilderFactory public static HtmlLayout.Builder newBuilder()
-
-