@Plugin(name="Gelf",
category="Core",
elementType="appender",
printObject=true)
public class GelfLogAppender
extends org.apache.logging.log4j.core.appender.AbstractAppender
true
, causing exceptions encountered while appending events to
be internally logged and then ignored. When set to false
exceptions will be propagated to the caller, instead.
You must set this to false when wrapping this Appender in a FailoverAppender
.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. |
DynamicMdcFieldType
rules to declare types with Regex Pattern
-based rules.
>DynamicMdcFieldType regex="business\..*\.field" type="double" /<
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:
Two values are set by the Log Appender:
append(LogEvent)
method is thread-safe and may be called by different threads at any time.Modifier and Type | Field and Description |
---|---|
protected GelfSender |
gelfSender |
Constructor and Description |
---|
GelfLogAppender(String name,
org.apache.logging.log4j.core.Filter filter,
MdcGelfMessageAssembler gelfMessageAssembler,
boolean ignoreExceptions) |
Modifier and Type | Method and Description |
---|---|
void |
append(org.apache.logging.log4j.core.LogEvent event) |
static GelfLogAppender |
createAppender(org.apache.logging.log4j.core.config.Configuration config,
String name,
org.apache.logging.log4j.core.Filter filter,
GelfLogField[] fields,
GelfDynamicMdcLogFields[] dynamicFieldArray,
GelfDynamicMdcFieldType[] dynamicFieldTypeArray,
String graylogHost,
String host,
String graylogPort,
String port,
String version,
String extractStackTrace,
String originHost,
String includeFullMdc,
String facility,
String filterStackTrace,
String mdcProfiling,
String maximumMessageSize,
String additionalFieldTypes,
boolean ignoreExceptions) |
protected GelfMessage |
createGelfMessage(org.apache.logging.log4j.core.LogEvent logEvent) |
protected GelfSender |
createGelfSender() |
void |
reportError(String message,
Exception exception) |
void |
start() |
protected boolean |
stop(long timeout,
TimeUnit timeUnit,
boolean changeLifeCycleState) |
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, requiresLocation, setHandler, toSerializable, toString
addFilter, getFilter, getPropertyArray, hasFilter, isFiltered, removeFilter, stop
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
protected GelfSender gelfSender
public GelfLogAppender(String name, org.apache.logging.log4j.core.Filter filter, MdcGelfMessageAssembler gelfMessageAssembler, boolean ignoreExceptions)
@PluginFactory public static GelfLogAppender createAppender(@PluginConfiguration org.apache.logging.log4j.core.config.Configuration config, @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, @PluginElement(value="DynamicMdcFieldTypes") GelfDynamicMdcFieldType[] dynamicFieldTypeArray, @PluginAttribute(value="graylogHost") String graylogHost, @PluginAttribute(value="host") String host, @PluginAttribute(value="graylogPort") String graylogPort, @PluginAttribute(value="port") String port, @PluginAttribute(value="version") String version, @PluginAttribute(value="extractStackTrace") String extractStackTrace, @PluginAttribute(value="originHost") String originHost, @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, @PluginAttribute(value="additionalFieldTypes") String additionalFieldTypes, @PluginAttribute(value="ignoreExceptions",defaultBoolean=true) boolean ignoreExceptions)
public void append(org.apache.logging.log4j.core.LogEvent event)
protected GelfMessage createGelfMessage(org.apache.logging.log4j.core.LogEvent logEvent)
protected boolean stop(long timeout, TimeUnit timeUnit, boolean changeLifeCycleState)
stop
in class org.apache.logging.log4j.core.filter.AbstractFilterable
public void start()
start
in interface org.apache.logging.log4j.core.LifeCycle
start
in class org.apache.logging.log4j.core.filter.AbstractFilterable
protected GelfSender createGelfSender()
Copyright © 2013–2023. All rights reserved.