src/main/java/org/graylog2/log4j2/GelfAppender.java
@PluginFactory
    @SuppressWarnings("unused")
    public static GelfAppender createGelfAppender(@PluginElement("Filter") Filter filter,
                                                  @PluginElement("Layout") Layout<? extends Serializable> layout,
                                                  @PluginElement(value = "AdditionalFields") final KeyValuePair[] additionalFields,
                                                  @PluginAttribute(value = "name") String name,
                                                  @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) Boolean ignoreExceptions,
                                                  @PluginAttribute(value = "server", defaultString = "localhost") String server,
                                                  @PluginAttribute(value = "port", defaultInt = 12201) Integer port,
                                                  @PluginAttribute(value = "protocol", defaultString = "UDP") String protocol,
                                                  @PluginAttribute(value = "hostName") String hostName,
                                                  @PluginAttribute(value = "queueSize", defaultInt = 512) Integer queueSize,
                                                  @PluginAttribute(value = "connectTimeout", defaultInt = 1000) Integer connectTimeout,
                                                  @PluginAttribute(value = "reconnectDelay", defaultInt = 500) Integer reconnectDelay,
                                                  @PluginAttribute(value = "sendBufferSize", defaultInt = -1) Integer sendBufferSize,
                                                  @PluginAttribute(value = "tcpNoDelay", defaultBoolean = false) Boolean tcpNoDelay,
                                                  @PluginAttribute(value = "tcpKeepAlive", defaultBoolean = false) Boolean tcpKeepAlive,
                                                  @PluginAttribute(value = "includeSource", defaultBoolean = true) Boolean includeSource,
                                                  @PluginAttribute(value = "includeThreadContext", defaultBoolean = true) Boolean includeThreadContext,
                                                  @PluginAttribute(value = "includeStackTrace", defaultBoolean = true) Boolean includeStackTrace,
                                                  @PluginAttribute(value = "includeExceptionCause", defaultBoolean = false) Boolean includeExceptionCause,
                                                  @PluginAttribute(value = "tlsEnabled", defaultBoolean = false) Boolean tlsEnabled,
                                                  @PluginAttribute(value = "tlsEnableCertificateVerification", defaultBoolean = true) Boolean tlsEnableCertificateVerification,
                                                  @PluginAttribute(value = "tlsTrustCertChainFilename") String tlsTrustCertChainFilename) {
        if (name == null) {
            LOGGER.error("No name provided for ConsoleAppender");
            return null;
        }

        if (!"UDP".equalsIgnoreCase(protocol) && !"TCP".equalsIgnoreCase(protocol)) {
            LOG.warn("Invalid protocol {}, falling back to UDP", protocol);
            protocol = "UDP";
        }
        if (hostName == null || hostName.trim().isEmpty()) {
            try {
                final String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName();
                if (isFQDN(canonicalHostName)) {
                    hostName = canonicalHostName;
                } else {
                    hostName = InetAddress.getLocalHost().getHostName();
                }
            } catch (UnknownHostException e) {
                LOG.warn("Couldn't detect local host name, falling back to \"localhost\"");
                hostName = "localhost";
            }
        }

        final InetSocketAddress serverAddress = new InetSocketAddress(server, port);
        final GelfTransports gelfProtocol = GelfTransports.valueOf(protocol.toUpperCase());
        final GelfConfiguration gelfConfiguration = new GelfConfiguration(serverAddress)
                .transport(gelfProtocol)
                .queueSize(queueSize)
                .connectTimeout(connectTimeout)
                .reconnectDelay(reconnectDelay)
                .sendBufferSize(sendBufferSize)
                .tcpNoDelay(tcpNoDelay)
                .tcpKeepAlive(tcpKeepAlive);

        if (tlsEnabled) {
            if (gelfProtocol.equals(GelfTransports.TCP)) {
                gelfConfiguration.enableTls();
                if (!tlsEnableCertificateVerification) {
                    LOG.warn("TLS certificate validation is disabled. This is unsecure!");
                    gelfConfiguration.disableTlsCertVerification();
                }
                if (tlsEnableCertificateVerification && tlsTrustCertChainFilename != null) {
                    gelfConfiguration.tlsTrustCertChainFile(new File(tlsTrustCertChainFilename));
                }
            } else {
                LOG.warn("Enabling of TLS is invalid for UDP Transport");
            }
        }

        return new GelfAppender(name, layout, filter, ignoreExceptions, gelfConfiguration, hostName, includeSource,
                includeThreadContext, includeStackTrace, additionalFields, includeExceptionCause);
    }
@PluginFactory
    @SuppressWarnings("unused")
    public static GelfAppender createGelfAppender(@PluginElement("Filter") Filter filter,
                                                  @PluginElement("Layout") Layout<? extends Serializable> layout,
                                                  @PluginElement(value = "AdditionalFields") final KeyValuePair[] additionalFields,
                                                  @PluginAttribute(value = "name") String name,
                                                  @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) Boolean ignoreExceptions,
                                                  @PluginAttribute(value = "server", defaultString = "localhost") String server,
                                                  @PluginAttribute(value = "port", defaultInt = 12201) Integer port,
                                                  @PluginAttribute(value = "protocol", defaultString = "UDP") String protocol,
                                                  @PluginAttribute(value = "hostName") String hostName,
                                                  @PluginAttribute(value = "queueSize", defaultInt = 512) Integer queueSize,
                                                  @PluginAttribute(value = "connectTimeout", defaultInt = 1000) Integer connectTimeout,
                                                  @PluginAttribute(value = "reconnectDelay", defaultInt = 500) Integer reconnectDelay,
                                                  @PluginAttribute(value = "sendBufferSize", defaultInt = -1) Integer sendBufferSize,
                                                  @PluginAttribute(value = "tcpNoDelay", defaultBoolean = false) Boolean tcpNoDelay,
                                                  @PluginAttribute(value = "tcpKeepAlive", defaultBoolean = false) Boolean tcpKeepAlive,
                                                  @PluginAttribute(value = "includeSource", defaultBoolean = true) Boolean includeSource,
                                                  @PluginAttribute(value = "includeThreadContext", defaultBoolean = true) Boolean includeThreadContext,
                                                  @PluginAttribute(value = "includeStackTrace", defaultBoolean = true) Boolean includeStackTrace,
                                                  @PluginAttribute(value = "includeExceptionCause", defaultBoolean = false) Boolean includeExceptionCause,
                                                  @PluginAttribute(value = "tlsEnabled", defaultBoolean = false) Boolean tlsEnabled,
                                                  @PluginAttribute(value = "tlsEnableCertificateVerification", defaultBoolean = true) Boolean tlsEnableCertificateVerification,
                                                  @PluginAttribute(value = "tlsTrustCertChainFilename") String tlsTrustCertChainFilename) {
        if (name == null) {
            LOGGER.error("No name provided for ConsoleAppender");
            return null;
        }

        if (!"UDP".equalsIgnoreCase(protocol) && !"TCP".equalsIgnoreCase(protocol)) {
            LOG.warn("Invalid protocol {}, falling back to UDP", protocol);
            protocol = "UDP";
        }
        if (hostName == null || hostName.trim().isEmpty()) {
            try {
                final String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName();
                if (isFQDN(canonicalHostName)) {
                    hostName = canonicalHostName;
                } else {
                    hostName = InetAddress.getLocalHost().getHostName();
                }
            } catch (UnknownHostException e) {
                LOG.warn("Couldn't detect local host name, falling back to \"localhost\"");
                hostName = "localhost";
            }
        }

        final InetSocketAddress serverAddress = new InetSocketAddress(server, port);
        final GelfTransports gelfProtocol = GelfTransports.valueOf(protocol.toUpperCase());
        final GelfConfiguration gelfConfiguration = new GelfConfiguration(serverAddress)
                .transport(gelfProtocol)
                .queueSize(queueSize)
                .connectTimeout(connectTimeout)
                .reconnectDelay(reconnectDelay)
                .sendBufferSize(sendBufferSize)
                .tcpNoDelay(tcpNoDelay)
                .tcpKeepAlive(tcpKeepAlive);

        if (tlsEnabled) {
            if (gelfProtocol.equals(GelfTransports.TCP)) {
                gelfConfiguration.enableTls();
                if (!tlsEnableCertificateVerification) {
                    LOG.warn("TLS certificate validation is disabled. This is unsecure!");
                    gelfConfiguration.disableTlsCertVerification();
                }
                if (tlsEnableCertificateVerification && tlsTrustCertChainFilename != null) {
                    gelfConfiguration.tlsTrustCertChainFile(new File(tlsTrustCertChainFilename));
                }
            } else {
                LOG.warn("Enabling of TLS is invalid for UDP Transport");
            }
        }

        return new GelfAppender(name, layout, filter, ignoreExceptions, gelfConfiguration, hostName, includeSource,
                includeThreadContext, includeStackTrace, additionalFields, includeExceptionCause);
    }
@ PluginFactory @ SuppressWarnings ( "unused" ) public static GelfAppender createGelfAppender ( @ PluginElement ( "Filter" ) Filter filter , @ PluginElement ( "Layout" ) Layout < ? extends Serializable > layout , @ PluginElement ( value = "AdditionalFields" ) final KeyValuePair [ ] additionalFields , @ PluginAttribute ( value = "name" ) String name , @ PluginAttribute ( value = "ignoreExceptions" , defaultBoolean = true ) Boolean ignoreExceptions , @ PluginAttribute ( value = "server" , defaultString = "localhost" ) String server , @ PluginAttribute ( value = "port" , defaultInt = 12201 ) Integer port , @ PluginAttribute ( value = "protocol" , defaultString = "UDP" ) String protocol , @ PluginAttribute ( value = "hostName" ) String hostName , @ PluginAttribute ( value = "queueSize" , defaultInt = 512 ) Integer queueSize , @ PluginAttribute ( value = "connectTimeout" , defaultInt = 1000 ) Integer connectTimeout , @ PluginAttribute ( value = "reconnectDelay" , defaultInt = 500 ) Integer reconnectDelay , @ PluginAttribute ( value = "sendBufferSize" , defaultInt = - 1 ) Integer sendBufferSize , @ PluginAttribute ( value = "tcpNoDelay" , defaultBoolean = false ) Boolean tcpNoDelay , @ PluginAttribute ( value = "tcpKeepAlive" , defaultBoolean = false ) Boolean tcpKeepAlive , @ PluginAttribute ( value = "includeSource" , defaultBoolean = true ) Boolean includeSource , @ PluginAttribute ( value = "includeThreadContext" , defaultBoolean = true ) Boolean includeThreadContext , @ PluginAttribute ( value = "includeStackTrace" , defaultBoolean = true ) Boolean includeStackTrace , @ PluginAttribute ( value = "includeExceptionCause" , defaultBoolean = false ) Boolean includeExceptionCause , @ PluginAttribute ( value = "tlsEnabled" , defaultBoolean = false ) Boolean tlsEnabled , @ PluginAttribute ( value = "tlsEnableCertificateVerification" , defaultBoolean = true ) Boolean tlsEnableCertificateVerification , @ PluginAttribute ( value = "tlsTrustCertChainFilename" ) String tlsTrustCertChainFilename ) { if ( name == null ) { LOGGER . error ( "No name provided for ConsoleAppender" ) ; return null ; } if ( ! "UDP" . equalsIgnoreCase ( protocol ) && ! "TCP" . equalsIgnoreCase ( protocol ) ) { LOG . warn ( "Invalid protocol {}, falling back to UDP" , protocol ) ; protocol = "UDP" ; } if ( hostName == null || hostName . trim ( ) . isEmpty ( ) ) { try { final String canonicalHostName = InetAddress . getLocalHost ( ) . getCanonicalHostName ( ) ; if ( isFQDN ( canonicalHostName ) ) { hostName = canonicalHostName ; } else { hostName = InetAddress . getLocalHost ( ) . getHostName ( ) ; } } catch ( UnknownHostException e ) { LOG . warn ( "Couldn't detect local host name, falling back to \"localhost\"" ) ; hostName = "localhost" ; } } final InetSocketAddress serverAddress = new InetSocketAddress ( server , port ) ; final GelfTransports gelfProtocol = GelfTransports . valueOf ( protocol . toUpperCase ( ) ) ; final GelfConfiguration gelfConfiguration = new GelfConfiguration ( serverAddress ) . transport ( gelfProtocol ) . queueSize ( queueSize ) . connectTimeout ( connectTimeout ) . reconnectDelay ( reconnectDelay ) . sendBufferSize ( sendBufferSize ) . tcpNoDelay ( tcpNoDelay ) . tcpKeepAlive ( tcpKeepAlive ) ; if ( tlsEnabled ) { if ( gelfProtocol . equals ( GelfTransports . TCP ) ) { gelfConfiguration . enableTls ( ) ; if ( ! tlsEnableCertificateVerification ) { LOG . warn ( "TLS certificate validation is disabled. This is unsecure!" ) ; gelfConfiguration . disableTlsCertVerification ( ) ; } if ( tlsEnableCertificateVerification && tlsTrustCertChainFilename != null ) { gelfConfiguration . tlsTrustCertChainFile ( new File ( tlsTrustCertChainFilename ) ) ; } } else { LOG . warn ( "Enabling of TLS is invalid for UDP Transport" ) ; } } return new GelfAppender ( name , layout , filter , ignoreExceptions , gelfConfiguration , hostName , includeSource , includeThreadContext , includeStackTrace , additionalFields , includeExceptionCause ) ; }
Factory method for creating a {@link GelfTransport} provider within the plugin manager.

@param name                             The name of the Appender.
@param filter                           A Filter to determine if the event should be handled by this Appender.
@param layout                           The Layout to use to format the LogEvent defaults to {@code "%m%n"}.
@param ignoreExceptions                 The default is {@code true}, causing exceptions encountered while appending events
to be internally logged and then ignored. When set to {@code false} exceptions will
be propagated to the caller, instead. Must be set to {@code false} when wrapping this
Appender in a {@link org.apache.logging.log4j.core.appender.FailoverAppender}.
@param server                           The server name of the GELF server, defaults to {@code localhost}.
@param port                             The port the GELF server is listening on, defaults to {@code 12201}.
@param hostName                         The host name of the machine generating the logs, defaults to local host name
or {@code localhost} if it couldn't be detected.
@param protocol                         The transport protocol to use, defaults to {@code UDP}.
@param tlsEnabled                       Whether TLS should be enabled, defaults to {@code false}.
@param tlsEnableCertificateVerification Whether TLS certificate chain should be checked, defaults to {@code true}.
@param tlsTrustCertChainFilename        A X.509 certificate chain file in PEM format for certificate verification, defaults to {@code null}
@param queueSize                        The size of the internally used queue, defaults to {@code 512}.
@param connectTimeout                   The connection timeout for TCP connections in milliseconds, defaults to {@code 1000}.
@param reconnectDelay                   The time to wait between reconnects in milliseconds, defaults to {@code 500}.
@param sendBufferSize                   The size of the socket send buffer in bytes, defaults to {@code -1} (deactivate).
@param tcpNoDelay                       Whether Nagle's algorithm should be used for TCP connections, defaults to {@code false}.
@param tcpKeepAlive                     Whether to try keeping alive TCP connections, defaults to {@code false}.
@param includeSource                    Whether the source of the log message should be included, defaults to {@code true}.
@param includeThreadContext             Whether the contents of the {@link org.apache.logging.log4j.ThreadContext} should be included, defaults to {@code true}.
@param includeStackTrace                Whether a full stack trace should be included, defaults to {@code true}.
@param includeExceptionCause            Whether the included stack trace should contain causing exceptions, defaults to {@code false}.
@param additionalFields                 Additional static key=value pairs that will be added to every log message.
@return a new GELF provider
Factory method for creating a { @link GelfTransport } provider within the plugin manager .