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:
LocationAware
,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 class
GelfLayout.Builder<B extends GelfLayout.Builder<B>>
static class
GelfLayout.CompressionType
private class
GelfLayout.FieldWriter
-
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 private KeyValuePair[]
additionalFields
private static char
C
private static int
COMPRESSION_THRESHOLD
private int
compressionThreshold
private GelfLayout.CompressionType
compressionType
private java.lang.String
host
private boolean
includeMapMessage
private boolean
includeNewLineDelimiter
private boolean
includeNullDelimiter
private boolean
includeStacktrace
private boolean
includeThreadContext
private PatternLayout
layout
private GelfLayout.FieldWriter
mapWriter
private GelfLayout.FieldWriter
mdcWriter
private static java.lang.ThreadLocal<java.lang.StringBuilder>
messageStringBuilder
private boolean
omitEmptyFields
private static char
Q
private static java.lang.String
QC
private static java.lang.String
QU
private static java.lang.ThreadLocal<java.lang.StringBuilder>
timestampStringBuilder
-
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 Modifier Constructor Description GelfLayout(java.lang.String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace)
Deprecated.UsenewBuilder()
insteadprivate
GelfLayout(Configuration config, java.lang.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, java.lang.String mdcPrefix, java.lang.String mapPrefix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private byte[]
compress(byte[] bytes)
static GelfLayout
createLayout(java.lang.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.private int
formatLevel(Level level)
http://en.wikipedia.org/wiki/Syslog#Severity_levels(package private) static java.lang.CharSequence
formatThrowable(java.lang.Throwable throwable)
Non-private to make it accessible from unit test.(package private) static java.lang.CharSequence
formatTimestamp(long timeMillis)
Non-private to make it accessible from unit test.java.util.Map<java.lang.String,java.lang.String>
getContentFormat()
Returns a description of the content format.java.lang.String
getContentType()
Returns the content type output by this layout.private static java.lang.StringBuilder
getMessageStringBuilder()
private static java.lang.StringBuilder
getTimestampStringBuilder()
static <B extends GelfLayout.Builder<B>>
BnewBuilder()
boolean
requiresLocation()
byte[]
toByteArray(LogEvent event)
Formats the Log Event as a byte array.private static java.lang.CharSequence
toNullSafeString(java.lang.CharSequence s)
java.lang.String
toSerializable(LogEvent event)
Formats the event as an Object that can be serialized.java.lang.String
toString()
private java.lang.StringBuilder
toText(LogEvent event, java.lang.StringBuilder builder, boolean gcFree)
private static boolean
valueNeedsLookup(java.lang.String value)
-
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
-
-
-
-
Field Detail
-
C
private static final char C
- See Also:
- Constant Field Values
-
COMPRESSION_THRESHOLD
private static final int COMPRESSION_THRESHOLD
- See Also:
- Constant Field Values
-
Q
private static final char Q
- See Also:
- Constant Field Values
-
QC
private static final java.lang.String QC
- See Also:
- Constant Field Values
-
QU
private static final java.lang.String QU
- See Also:
- Constant Field Values
-
additionalFields
private final KeyValuePair[] additionalFields
-
compressionThreshold
private final int compressionThreshold
-
compressionType
private final GelfLayout.CompressionType compressionType
-
host
private final java.lang.String 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
private final PatternLayout layout
-
mdcWriter
private final GelfLayout.FieldWriter mdcWriter
-
mapWriter
private final GelfLayout.FieldWriter mapWriter
-
messageStringBuilder
private static final java.lang.ThreadLocal<java.lang.StringBuilder> messageStringBuilder
-
timestampStringBuilder
private static final java.lang.ThreadLocal<java.lang.StringBuilder> timestampStringBuilder
-
-
Constructor Detail
-
GelfLayout
@Deprecated public GelfLayout(java.lang.String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold, boolean includeStacktrace)
Deprecated.UsenewBuilder()
instead
-
GelfLayout
private GelfLayout(Configuration config, java.lang.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, java.lang.String mdcPrefix, java.lang.String mapPrefix)
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
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:Layout
Returns a description of the content format.- Specified by:
getContentFormat
in interfaceLayout<java.lang.String>
- Overrides:
getContentFormat
in 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:Layout
Returns the content type output by this layout. The base class returns "text/plain".- Specified by:
getContentType
in interfaceLayout<java.lang.String>
- Overrides:
getContentType
in classAbstractStringLayout
- Returns:
- The default content type for Strings.
-
toByteArray
public byte[] toByteArray(LogEvent event)
Description copied from class:AbstractStringLayout
Formats the Log Event as a byte array.- Specified by:
toByteArray
in interfaceLayout<java.lang.String>
- Overrides:
toByteArray
in 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: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 {
- Specified by:
encode
in interfaceEncoder<LogEvent>
- Overrides:
encode
in classAbstractLayout<java.lang.String>
- Parameters:
event
- the LogEvent to encode.destination
- holds the ByteBuffer to write into.- See Also:
AbstractStringLayout.getStringBuilder()
,AbstractStringLayout.getStringBuilderEncoder()
-
requiresLocation
public boolean requiresLocation()
- Specified by:
requiresLocation
in interfaceLocationAware
- Overrides:
requiresLocation
in classAbstractStringLayout
-
compress
private byte[] compress(byte[] bytes)
-
toSerializable
public java.lang.String toSerializable(LogEvent event)
Description copied from interface:Layout
Formats the event as an Object that can be serialized.- Parameters:
event
- The Logging Event.- Returns:
- The formatted event.
-
toText
private java.lang.StringBuilder toText(LogEvent event, java.lang.StringBuilder builder, boolean gcFree)
-
valueNeedsLookup
private static boolean valueNeedsLookup(java.lang.String value)
-
getMessageStringBuilder
private static java.lang.StringBuilder getMessageStringBuilder()
-
toNullSafeString
private static java.lang.CharSequence toNullSafeString(java.lang.CharSequence s)
-
formatTimestamp
static java.lang.CharSequence formatTimestamp(long timeMillis)
Non-private to make it accessible from unit test.
-
getTimestampStringBuilder
private static java.lang.StringBuilder getTimestampStringBuilder()
-
formatLevel
private int formatLevel(Level level)
http://en.wikipedia.org/wiki/Syslog#Severity_levels
-
formatThrowable
static java.lang.CharSequence formatThrowable(java.lang.Throwable throwable)
Non-private to make it accessible from unit test.
-
-