Class GelfLayout
java.lang.Object
org.apache.logging.log4j.core.layout.AbstractLayout<String>
org.apache.logging.log4j.core.layout.AbstractStringLayout
org.apache.logging.log4j.core.layout.GelfLayout
- All Implemented Interfaces:
LocationAware
,Layout<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 (the compressionThreshold
).
This layout does not implement chunking.
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
GelfLayout.Builder<B extends GelfLayout.Builder<B>>
static enum
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
ConstructorDescriptionGelfLayout
(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionstatic GelfLayout
createLayout
(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace) Deprecated.UsenewBuilder()
insteadvoid
encode
(LogEvent event, ByteBufferDestination destination) Encodes the specified source LogEvent to some binary representation and writes the result to the specified destination.Returns a description of the content format.Returns the content type output by this layout.static <B extends GelfLayout.Builder<B>>
Bboolean
byte[]
toByteArray
(LogEvent event) Formats the Log Event as a byte array.toSerializable
(LogEvent event) Formats the event as an Object that can be serialized.toString()
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 Details
-
GelfLayout
@Deprecated public GelfLayout(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace) Deprecated.UsenewBuilder()
instead
-
-
Method Details
-
toString
-
createLayout
@Deprecated public static GelfLayout createLayout(@PluginAttribute("host") 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
-
getContentFormat
Description copied from interface:Layout
Returns a description of the content format.- Specified by:
getContentFormat
in interfaceLayout<String>
- Overrides:
getContentFormat
in classAbstractLayout<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
Description copied from interface:Layout
Returns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentType
in interfaceLayout<String>
- Overrides:
getContentType
in classAbstractStringLayout
- Returns:
- The default content type for Strings.
-
toByteArray
Description copied from class:AbstractStringLayout
Formats the Log Event as a byte array.- Specified by:
toByteArray
in interfaceLayout<String>
- Overrides:
toByteArray
in classAbstractStringLayout
- Parameters:
event
- The Log Event.- Returns:
- The formatted event as a byte array.
-
encode
Description copied from class:AbstractLayout
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 { @Override public void encode(LogEvent event, ByteBufferDestination destination) { StringBuilder text = getStringBuilder(); convertLogEventToText(event, text); getStringBuilderEncoder().encode(text, destination); } private void convertLogEventToText(LogEvent event, StringBuilder destination) { ... // append a text representation of the log event to the StringBuilder } }
-
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocation
in interfaceLocationAware
- Overrides:
requiresLocation
in classAbstractStringLayout
-
toSerializable
Description copied from interface:Layout
Formats the event as an Object that can be serialized.- Parameters:
event
- The Logging Event.- Returns:
- The formatted event.
-
newBuilder()
instead