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
Nested ClassesModifier and TypeClassDescriptionstatic classGelfLayout.Builder<B extends GelfLayout.Builder<B>>static enumprivate classNested classes/interfaces inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
AbstractStringLayout.Serializer, AbstractStringLayout.Serializer2 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final KeyValuePair[]private static final charprivate static final intprivate final intprivate final GelfLayout.CompressionTypeprivate final Stringprivate final booleanprivate final booleanprivate final booleanprivate final booleanprivate final booleanprivate final PatternLayoutprivate final GelfLayout.FieldWriterprivate final GelfLayout.FieldWriterprivate static final ThreadLocal<StringBuilder> private final booleanprivate static final charprivate static final Stringprivate static final Stringprivate static final ThreadLocal<StringBuilder> Fields inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
DEFAULT_STRING_BUILDER_SIZE, MAX_STRING_BUILDER_SIZEFields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
configuration, eventCount, footer, header, LOGGERFields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE -
Constructor Summary
ConstructorsModifierConstructorDescriptionGelfLayout(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace) Deprecated.privateGelfLayout(Configuration config, String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace, boolean includeThreadContext, boolean includeMapMessage, boolean includeNullDelimiter, boolean includeNewLineDelimiter, boolean omitEmptyFields, ListChecker mdcChecker, ListChecker mapChecker, PatternLayout patternLayout, String mdcPrefix, String mapPrefix) -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]compress(byte[] bytes) static GelfLayoutcreateLayout(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.private intformatLevel(Level level) http://en.wikipedia.org/wiki/Syslog#Severity_levels(package private) static CharSequenceformatThrowable(Throwable throwable) Non-private to make it accessible from unit test.(package private) static CharSequenceformatTimestamp(long timeMillis) Non-private to make it accessible from unit test.Returns a description of the content format.Returns the content type output by this layout.private static StringBuilderprivate static StringBuilderstatic <B extends GelfLayout.Builder<B>>
Bbooleanbyte[]toByteArray(LogEvent event) Formats the Log Event as a byte array.private static CharSequencetoSerializable(LogEvent event) Formats the event as an Object that can be serialized.toString()private StringBuildertoText(LogEvent event, StringBuilder builder, boolean gcFree) private static booleanvalueNeedsLookup(String value) Methods inherited from class org.apache.logging.log4j.core.layout.AbstractStringLayout
getBytes, getCharset, getFooter, getFooterSerializer, getHeader, getHeaderSerializer, getStringBuilder, getStringBuilderEncoder, serializeToBytes, serializeToString, trimToMaxSizeMethods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
getConfiguration, markEvent
-
Field Details
-
C
private static final char C- See Also:
-
COMPRESSION_THRESHOLD
private static final int COMPRESSION_THRESHOLD- See Also:
-
Q
private static final char Q- See Also:
-
QC
- See Also:
-
QU
- See Also:
-
additionalFields
-
compressionThreshold
private final int compressionThreshold -
compressionType
-
host
-
includeStacktrace
private final boolean includeStacktrace -
includeThreadContext
private final boolean includeThreadContext -
includeMapMessage
private final boolean includeMapMessage -
includeNullDelimiter
private final boolean includeNullDelimiter -
includeNewLineDelimiter
private final boolean includeNewLineDelimiter -
omitEmptyFields
private final boolean omitEmptyFields -
layout
-
mdcWriter
-
mapWriter
-
messageStringBuilder
-
timestampStringBuilder
-
-
Constructor Details
-
GelfLayout
@Deprecated public GelfLayout(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace) Deprecated.UsenewBuilder()instead -
GelfLayout
private GelfLayout(Configuration config, String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace, boolean includeThreadContext, boolean includeMapMessage, boolean includeNullDelimiter, boolean includeNewLineDelimiter, boolean omitEmptyFields, ListChecker mdcChecker, ListChecker mapChecker, PatternLayout patternLayout, String mdcPrefix, String mapPrefix)
-
-
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:LayoutReturns a description of the content format.- Specified by:
getContentFormatin interfaceLayout<String>- Overrides:
getContentFormatin 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:LayoutReturns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentTypein interfaceLayout<String>- Overrides:
getContentTypein classAbstractStringLayout- Returns:
- The default content type for Strings.
-
toByteArray
Description copied from class:AbstractStringLayoutFormats the Log Event as a byte array.- Specified by:
toByteArrayin interfaceLayout<String>- Overrides:
toByteArrayin classAbstractStringLayout- Parameters:
event- The Log Event.- Returns:
- The formatted event as a byte array.
-
encode
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 { -
requiresLocation
public boolean requiresLocation()- Specified by:
requiresLocationin interfaceLocationAware- Overrides:
requiresLocationin classAbstractStringLayout
-
compress
private byte[] compress(byte[] bytes) -
toSerializable
Description copied from interface:LayoutFormats the event as an Object that can be serialized.- Parameters:
event- The Logging Event.- Returns:
- The formatted event.
-
toText
-
valueNeedsLookup
-
getMessageStringBuilder
-
toNullSafeString
-
formatTimestamp
Non-private to make it accessible from unit test. -
getTimestampStringBuilder
-
formatLevel
http://en.wikipedia.org/wiki/Syslog#Severity_levels -
formatThrowable
Non-private to make it accessible from unit test.
-
newBuilder()instead