@Plugin(name="Gelf",
category="Core",
elementType="appender",
printObject=true)
public class GelfLogAppender
extends org.apache.logging.log4j.core.appender.AbstractAppender
implements ErrorReporter
Log4j v2 supports an extensive and flexible configuration in contrast to other log frameworks (JUL, log4j v1). This allows you to specify your needed fields you want to use in the GELF message. An empty field configuration results in a message containing only
You can add different fields:
<Field name="fieldName1" literal="your literal value" />
<Field name="fieldName1" mdc="name of the MDC entry" />
<DynamicMdcFields regex="mdc.*" />
See also: Pattern Layout
You can use all built-in Pattern Fields:
<Field name="simpleClassName" pattern="%C{1}" />
<Field name="timestamp" pattern="%d{dd MMM yyyy HH:mm:ss,SSS}" />
<Field name="level" pattern="%level" />
Additionally, you can add the host-Field, which can supply you either the FQDN hostname, the simple hostname or the local address.
| Option | Description |
|---|---|
|
host {["fqdn" |"simple" |"address"]} |
Outputs either the FQDN hostname, the simple hostname or the local address. You can follow the throwable conversion word with an option in the form %host{option}. %host{fqdn} default setting, outputs the FQDN hostname, e.g. www.you.host.name.com. %host{simple} outputs simple hostname, e.g. www. %host{address} outputs the local IP address of the found hostname, e.g. 1.2.3.4 or affe:affe:affe::1. |
MDC Profiling allows to calculate the runtime from request start up to the time until the log message was generated. You must set one value in the MDC:
| Modifier and Type | Field and Description |
|---|---|
protected GelfSender |
gelfSender |
| Constructor and Description |
|---|
GelfLogAppender(String name,
org.apache.logging.log4j.core.Filter filter,
MdcGelfMessageAssembler gelfMessageAssembler) |
| Modifier and Type | Method and Description |
|---|---|
void |
append(org.apache.logging.log4j.core.LogEvent event) |
static GelfLogAppender |
createAppender(String name,
org.apache.logging.log4j.core.Filter filter,
GelfLogField[] fields,
GelfDynamicMdcLogFields[] dynamicFieldArray,
String graylogHost,
String host,
String graylogPort,
String port,
String extractStackTrace,
String includeFullMdc,
String facility,
String filterStackTrace,
String mdcProfiling,
String maximumMessageSize) |
protected GelfMessage |
createGelfMessage(org.apache.logging.log4j.core.LogEvent logEvent) |
void |
reportError(String message,
Exception exception)
Report an error caused by a exception.
|
void |
start() |
void |
stop() |
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, setHandler, toStringaddFilter, getFilter, hasFilter, isFiltered, removeFiltergetState, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStoppingprotected GelfSender gelfSender
public GelfLogAppender(String name, org.apache.logging.log4j.core.Filter filter, MdcGelfMessageAssembler gelfMessageAssembler)
@PluginFactory public static GelfLogAppender createAppender(@PluginAttribute(value="name") String name, @PluginElement(value="Filter") org.apache.logging.log4j.core.Filter filter, @PluginElement(value="Field") GelfLogField[] fields, @PluginElement(value="DynamicMdcFields") GelfDynamicMdcLogFields[] dynamicFieldArray, @PluginAttribute(value="graylogHost") String graylogHost, @PluginAttribute(value="host") String host, @PluginAttribute(value="graylogPort") String graylogPort, @PluginAttribute(value="port") String port, @PluginAttribute(value="extractStackTrace") String extractStackTrace, @PluginAttribute(value="includeFullMdc") String includeFullMdc, @PluginAttribute(value="facility") String facility, @PluginAttribute(value="filterStackTrace") String filterStackTrace, @PluginAttribute(value="mdcProfiling") String mdcProfiling, @PluginAttribute(value="maximumMessageSize") String maximumMessageSize)
name - filter - fields - graylogHost - host - graylogPort - port - extractStackTrace - facility - filterStackTrace - mdcProfiling - maximumMessageSize - public void append(org.apache.logging.log4j.core.LogEvent event)
append in interface org.apache.logging.log4j.core.Appenderprotected GelfMessage createGelfMessage(org.apache.logging.log4j.core.LogEvent logEvent)
public void reportError(String message, Exception exception)
ErrorReporterreportError in interface ErrorReporterpublic void stop()
stop in interface org.apache.logging.log4j.core.LifeCyclestop in class org.apache.logging.log4j.core.filter.AbstractFilterablepublic void start()
start in interface org.apache.logging.log4j.core.LifeCyclestart in class org.apache.logging.log4j.core.filter.AbstractFilterableCopyright © 2013-2014. All Rights Reserved.