Class GelfLayout
- 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.GelfLayout
-
- All Implemented Interfaces:
Layout<java.lang.String>,Encoder<LogEvent>,StringLayout
@Plugin(name="GelfLayout", category="Core", elementType="layout", printObject=true) public final class GelfLayout extends AbstractStringLayout
Lays out events in the Graylog Extended Log Format (GELF) 1.1.This layout compresses JSON to GZIP or ZLIB (the
compressionType) if log event data is larger than 1024 bytes (thecompressionThreshold). This layout does not implement chunking.- See Also:
- GELF specification
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGelfLayout.Builder<B extends GelfLayout.Builder<B>>static classGelfLayout.CompressionType-
Nested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2
-
-
Field Summary
-
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
-
-
Constructor Summary
Constructors Constructor Description GelfLayout(java.lang.String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace)Deprecated.UsenewBuilder()instead
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static GelfLayoutcreateLayout(java.lang.String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace)Deprecated.UsenewBuilder()insteadvoidencode(LogEvent event, ByteBufferDestination destination)Encodes the specified source LogEvent to some binary representation and writes the result to the specified destination.java.util.Map<java.lang.String,java.lang.String>getContentFormat()Returns a description of the content format.java.lang.StringgetContentType()Returns the content type output by this layout.static <B extends GelfLayout.Builder<B>>
BnewBuilder()byte[]toByteArray(LogEvent event)Formats the Log Event as a byte array.java.lang.StringtoSerializable(LogEvent event)Formats the event as an Object that can be serialized.-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, serializeToBytes, serializeToString, trimToMaxSize
-
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
getConfiguration, markEvent
-
-
-
-
Constructor Detail
-
GelfLayout
@Deprecated public GelfLayout(java.lang.String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace)Deprecated.UsenewBuilder()instead
-
-
Method Detail
-
createLayout
@Deprecated public static GelfLayout createLayout(@PluginAttribute("host") java.lang.String host, @PluginElement("AdditionalField") KeyValuePair[] additionalFields, @PluginAttribute(value="compressionType",defaultString="GZIP") GelfLayout.CompressionType compressionType, @PluginAttribute(value="compressionThreshold",defaultInt=1024) int compressionThreshold, @PluginAttribute(value="includeStacktrace",defaultBoolean=true) boolean includeStacktrace)
Deprecated.UsenewBuilder()instead
-
newBuilder
@PluginBuilderFactory public static <B extends GelfLayout.Builder<B>> B newBuilder()
-
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<java.lang.String>- Overrides:
getContentFormatin classAbstractLayout<java.lang.String>- Returns:
- a Map of key/value pairs describing the Layout-specific content format, or an empty Map if no content format descriptors are specified.
-
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.
-
toByteArray
public byte[] toByteArray(LogEvent event)
Description copied from class:AbstractStringLayoutFormats the Log Event as a byte array.- Specified by:
toByteArrayin interfaceLayout<java.lang.String>- Overrides:
toByteArrayin classAbstractStringLayout- Parameters:
event- The Log Event.- Returns:
- The formatted event as a byte array.
-
encode
public void encode(LogEvent event, ByteBufferDestination destination)
Description copied from class:AbstractLayoutEncodes 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<LogEvent>- Overrides:
encodein classAbstractLayout<java.lang.String>- Parameters:
event- the LogEvent to encode.destination- holds the ByteBuffer to write into.- See Also:
AbstractStringLayout.getStringBuilder(),AbstractStringLayout.getStringBuilderEncoder()
-
-