Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mp911de/logstash-gelf

Graylog Extended Log Format (GELF) implementation in Java for all major logging frameworks: log4j, log4j2, java.util.logging, logback, JBossAS7 and WildFly 8-12
https://github.com/mp911de/logstash-gelf

gelf graylog java log4j logback logstash

Last synced: 1 day ago
JSON representation

Graylog Extended Log Format (GELF) implementation in Java for all major logging frameworks: log4j, log4j2, java.util.logging, logback, JBossAS7 and WildFly 8-12

Awesome Lists containing this project

README

        

logstash-gelf
=========================

**This project is now archived, after a decade of maintenance, with 36 releases and several occasional contributors. The project is feature complete, and we see little issue traffic. With me being the sole maintainer, it is about time to turn off the lights here and move on to free up time for other duties. K, thx, good bye.**

[![Join the chat at https://gitter.im/mp911de/logstash-gelf](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/mp911de/logstash-gelf?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[![Maven Central](https://maven-badges.herokuapp.com/maven-central/biz.paluch.logging/logstash-gelf/badge.svg)](https://maven-badges.herokuapp.com/maven-central/biz.paluch.logging/logstash-gelf)

Provides logging to logstash using the Graylog Extended Logging Format ([GELF](http://www.graylog2.org/resources/gelf/specification) 1.0 and 1.1) for using with:

* [Java Util Logging](#java-util-logging-gelf-configuration)
* [Glassfish/Payara](#glassfishpayara-configuration)
* [log4j 2.x](#log4j2-gelf-configuration)
* [WildFly](#wildfly-configuration)
* [Thorntail (WildFly Swarm 2.x)](#thorntail-wildfly-swarm-2x-configuration)
* [Logback](#logback-gelf-configuration)

`logstash-gelf` requires as of version 1.14.0 Java 7 or higher. Version 1.13.x and older require Java 6.
See also http://logging.paluch.biz/ or http://www.graylog2.org/resources/gelf/specification for further documentation.

Including it in your project
--------------

Maven:
```xml

biz.paluch.logging
logstash-gelf
x.y.z

```

Direct download from [Maven Central](http://search.maven.org/remotecontent?filepath=biz/paluch/logging/logstash-gelf/1.12.0/logstash-gelf-1.12.0.jar)

JBoss AS/WildFly Module Download:

```xml

biz.paluch.logging
logstash-gelf
x.y.z
logging-module

```

Direct download from [Maven Central](http://search.maven.org/remotecontent?filepath=biz/paluch/logging/logstash-gelf/1.12.0/logstash-gelf-1.12.0-logging-module.zip)

Using snapshot builds:

```xml

biz.paluch.logging
logstash-gelf
x.y.z-SNAPSHOT


sonatype-nexus-snapshots
https://oss.sonatype.org/content/repositories/snapshots

true

```

Java Util Logging GELF configuration
--------------

**Properties**

```properties
handlers = biz.paluch.logging.gelf.jul.GelfLogHandler, java.util.logging.ConsoleHandler

.handlers = biz.paluch.logging.gelf.jul.GelfLogHandler, java.util.logging.ConsoleHandler
.level = INFO

biz.paluch.logging.gelf.jul.GelfLogHandler.host=udp:localhost
biz.paluch.logging.gelf.jul.GelfLogHandler.port=12201
biz.paluch.logging.gelf.jul.GelfLogHandler.version=1.1
biz.paluch.logging.gelf.jul.GelfLogHandler.facility=java-test
biz.paluch.logging.gelf.jul.GelfLogHandler.extractStackTrace=true
biz.paluch.logging.gelf.jul.GelfLogHandler.filterStackTrace=true
biz.paluch.logging.gelf.jul.GelfLogHandler.timestampPattern=yyyy-MM-dd HH:mm:ss,SSS
biz.paluch.logging.gelf.jul.GelfLogHandler.maximumMessageSize=8192

# This are static fields
biz.paluch.logging.gelf.jul.GelfLogHandler.additionalFields=fieldName1=fieldValue1,fieldName2=fieldValue2
# Optional: Specify field types
biz.paluch.logging.gelf.jul.GelfLogHandler.additionalFieldTypes=fieldName1=String,fieldName2=Double,fieldName3=Long
biz.paluch.logging.gelf.jul.GelfLogHandler.level=INFO
```

Glassfish/Payara configuration
-------------
Install the library with its dependencies (see download above) in Glassfish. Place it below the `$GFHOME/glassfish/domains/$YOURDOMAIN/lib/ext/` path, then add the [Java Util Logging](#jul) to your `logging.properties` file.

**Properties**

```properties
log4j.appender.gelf=biz.paluch.logging.gelf.log4j.GelfLogAppender
log4j.appender.gelf.Threshold=INFO
log4j.appender.gelf.Host=udp:localhost
log4j.appender.gelf.Port=12201
log4j.appender.gelf.Version=1.1
log4j.appender.gelf.Facility=java-test
log4j.appender.gelf.ExtractStackTrace=true
log4j.appender.gelf.FilterStackTrace=true
log4j.appender.gelf.MdcProfiling=true
log4j.appender.gelf.TimestampPattern=yyyy-MM-dd HH:mm:ss,SSS
log4j.appender.gelf.MaximumMessageSize=8192

# This are static fields
log4j.appender.gelf.AdditionalFields=fieldName1=fieldValue1,fieldName2=fieldValue2
# Optional: Specify field types
log4j.appender.gelf.AdditionalFieldTypes=fieldName1=String,fieldName2=Double,fieldName3=Long

# This are fields using MDC
log4j.appender.gelf.MdcFields=mdcField1,mdcField2
log4j.appender.gelf.DynamicMdcFields=mdc.*,(mdc|MDC)fields
log4j.appender.gelf.DynamicMdcFieldTypes=my_field.*=String,business\..*\.field=double
log4j.appender.gelf.IncludeFullMdc=true
```

**XML**

```xml





















```

log4j2 GELF configuration
-------------------------

### Fields

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

* timestamp
* level (syslog level)
* host
* facility
* message
* short_message

You can add different fields:

* Static Literals
* MDC Fields
* Log-Event fields (using Pattern Layout)

In order to do so, use nested Field elements below the Appender element.

### Static Literals

```xml

```

### MDC Fields

```xml

```

### Dynamic MDC Fields

```xml

```

In contrast to the configuration of other log frameworks log4j2 config uses one `DynamicMdcFields` element per regex (not separated by comma).

### Log-Event fields

See also: [Pattern Layout](http://logging.apache.org/log4j/2.x/manual/layouts.html#PatternLayout)

Set the desired pattern and the field will be sent using the specified pattern value.

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.

**XML**

```xml


























```

**YAML**

```yaml
rootLogger:
level: INFO
appenderRef.gelf.ref: GelfAppender

appender.gelf:
type: Gelf
name: GelfAppender
host: udp:localhost
port: 12201
version: 1.0
includeFullMdc: true
mdcProfiling: true
maximumMessageSize: 32768
dynamicMdcFields:
type: DynamicMdcFields
regex: "mdc.*,(mdc|MDC)fields"
field:
- name: fieldName2
literal: fieldName2 # This is a static field
- name: className
pattern: "%C"
- name: lineNumber
pattern: "%line"
```

JBoss AS7 configuration
-----------------------
Include the library as module (see download above), then add following lines to your configuration:

**standalone.xml**

```xml























...






```

WildFly configuration
--------------------------------------------
Include the library as module (see download above). Place it below the `$JBOSS_HOME/modules/system/layers/base` path, then add following lines to your configuration:

standalone.xml
```xml























...






```

Thorntail (WildFly Swarm 2.x) configuration
--------------------------------------------
Include `module-thorntail.xml` from the logging module zip (see download above). Place it below the `src/main/resources/modules/biz/paluch/logging/main` path as `module.xml`, then add following lines to your `project-stages.yml`:

`project-stages.yml`:
```yaml
swarm:
logging:
custom-handlers:
GelfLogger:
attribute-class: biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler
module: biz.paluch.logging
properties:
host: "udp:localhost"
port: 12201
version: "1.0"
facility: "java-test"
extractStackTrace: true
filterStackTrace: true
includeLocation: true
mdcProfiling: true
timestampPattern: "yyyy-MM-dd HH:mm:ss,SSS"
maximumMessageSize: 8192
additionalFields: "fieldName1=fieldValue1,fieldName2=fieldValue2"
additionalFieldTypes: "my_field.*=String,business\..*\.field=double"
MdcFields: "mdcField1,mdcField2"
dynamicMdcFields: "mdc.*,(mdc|MDC)fields"
includeFullMdc: true
root-logger:
level: INFO
handlers:
- GelfLogger
```

Logback GELF configuration
--------------------------
logback.xml Example:

```xml

test


udp:localhost
12201
1.1
java-test
true
true
true
yyyy-MM-dd HH:mm:ss,SSS
8192


fieldName1=fieldValue1,fieldName2=fieldValue2

fieldName1=String,fieldName2=Double,fieldName3=Long


mdcField1,mdcField2
mdc.*,(mdc|MDC)fields
my_field.*=String,business\..*\.field=double
true

INFO



```

License
-------
* [The MIT License (MIT)](http://opensource.org/licenses/MIT)
* Contains also code from https://github.com/t0xa/gelfj

Contributing
------------
Github is for social coding: if you want to write code, I encourage contributions through pull requests from forks of this repository.
Create Github tickets for bugs and new features and comment on the ones that you are interested in and take a look into [CONTRIBUTING.md](https://github.com/mp911de/logstash-gelf/blob/main/.github/CONTRIBUTING.md)