org.apache.logging.log4j.core.layout
Class GelfLayout

java.lang.Object
  extended by org.apache.logging.log4j.core.layout.AbstractLayout<String>
      extended by org.apache.logging.log4j.core.layout.AbstractStringLayout
          extended by org.apache.logging.log4j.core.layout.GelfLayout
All Implemented Interfaces:
Serializable, Layout<String>

@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.

Configure as follows to send to a Graylog2 server:

 <Appenders>
        <Socket name="Graylog" protocol="udp" host="graylog.domain.com" port="12201">
            <GelfLayout host="someserver" compressionType="GZIP" compressionThreshold="1024">
                <KeyValuePair key="additionalField1" value="additional value 1"/>
                <KeyValuePair key="additionalField2" value="additional value 2"/>
            </GelfLayout>
        </Socket>
 </Appenders>
 

See Also:
GELF home page, GELF specification, Serialized Form

Nested Class Summary
static class GelfLayout.CompressionType
           
 
Field Summary
 
Fields inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
footer, header, LOGGER
 
Fields inherited from interface org.apache.logging.log4j.core.Layout
ELEMENT_TYPE
 
Constructor Summary
GelfLayout(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold)
           
 
Method Summary
static GelfLayout createLayout(String host, KeyValuePair[] additionalFields, GelfLayout.CompressionType compressionType, int compressionThreshold)
           
 Map<String,String> getContentFormat()
          Returns a description of the content format.
 String getContentType()
          Returns the content type output by this layout.
 byte[] toByteArray(LogEvent event)
          Formats the Log Event as a byte array.
 String toSerializable(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
 
Methods inherited from class org.apache.logging.log4j.core.layout.AbstractLayout
getFooter, getHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GelfLayout

public GelfLayout(String host,
                  KeyValuePair[] additionalFields,
                  GelfLayout.CompressionType compressionType,
                  int compressionThreshold)
Method Detail

createLayout

@PluginFactory
public static GelfLayout createLayout(@PluginAttribute(value="host")
                                                    String host,
                                                    @PluginElement(value="AdditionalField")
                                                    KeyValuePair[] additionalFields,
                                                    @PluginAttribute(value="compressionType",defaultString="GZIP")
                                                    GelfLayout.CompressionType compressionType,
                                                    @PluginAttribute(value="compressionThreshold",defaultInt=1024)
                                                    int compressionThreshold)

getContentFormat

public Map<String,String> getContentFormat()
Description copied from interface: Layout
Returns a description of the content format.

Specified by:
getContentFormat in interface Layout<String>
Overrides:
getContentFormat in class AbstractLayout<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 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 interface Layout<String>
Overrides:
getContentType in class AbstractStringLayout
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 interface Layout<String>
Overrides:
toByteArray in class AbstractStringLayout
Parameters:
event - The Log Event.
Returns:
The formatted event as a byte array.

toSerializable

public 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.


Copyright © 1999-2015 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.