• This repository has been archived on 29/Jun/2023
  • Stars
    star
    415
  • Rank 104,007 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

Maven Central

Provides logging to logstash using the Graylog Extended Logging Format (GELF 1.0 and 1.1) for using with:

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:

<dependency>
    <groupId>biz.paluch.logging</groupId>
    <artifactId>logstash-gelf</artifactId>
    <version>x.y.z</version>
</dependency>

Direct download from Maven Central

JBoss AS/WildFly Module Download:

<dependency>
    <groupId>biz.paluch.logging</groupId>
    <artifactId>logstash-gelf</artifactId>
    <version>x.y.z</version>
    <classifier>logging-module</classifier>
</dependency>

Direct download from Maven Central

Using snapshot builds:

<dependency>
    <groupId>biz.paluch.logging</groupId>
    <artifactId>logstash-gelf</artifactId>
    <version>x.y.z-SNAPSHOT</version>
</dependency>

<repositories>
    <repository>
        <id>sonatype-nexus-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Java Util Logging GELF configuration

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 to your logging.properties file.

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

<appender name="gelf" class="biz.paluch.logging.gelf.log4j.GelfLogAppender">
    <param name="Threshold" value="INFO" />
    <param name="Host" value="udp:localhost" />
    <param name="Port" value="12201" />
    <param name="Version" value="1.1" />
    <param name="Facility" value="java-test" />
    <param name="ExtractStackTrace" value="true" />
    <param name="FilterStackTrace" value="true" />
    <param name="MdcProfiling" value="true" />
    <param name="TimestampPattern" value="yyyy-MM-dd HH:mm:ss,SSS" />
    <param name="MaximumMessageSize" value="8192" />
    
    <!-- This are static fields -->
    <param name="AdditionalFields" value="fieldName1=fieldValue1,fieldName2=fieldValue2" />
    <!-- Optional: Specify field types -->
    <param name="AdditionalFieldTypes" value="fieldName1=String,fieldName2=Double,fieldName3=Long" />
    
    <!-- This are fields using MDC -->
    <param name="MdcFields" value="mdcField1,mdcField2" />
    <param name="DynamicMdcFields" value="mdc.*,(mdc|MDC)fields" />
    <param name="DynamicMdcFieldTypes" value="my_field.*=String,business\..*\.field=double" />
    <param name="IncludeFullMdc" value="true" />
</appender>

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

<Field name="fieldName1" literal="your literal value" />

MDC Fields

<Field name="fieldName1" mdc="name of the MDC entry" />

Dynamic MDC Fields

<DynamicMdcFields regex="mdc.*" />

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

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

<Configuration packages="biz.paluch.logging.gelf.log4j2">
    <Appenders>
        <Gelf name="gelf" host="udp:localhost" port="12201" version="1.1" extractStackTrace="true"
              filterStackTrace="true" mdcProfiling="true" includeFullMdc="true" maximumMessageSize="8192"
              originHost="%host{fqdn}" additionalFieldTypes="fieldName1=String,fieldName2=Double,fieldName3=Long">
            <Field name="timestamp" pattern="%d{dd MMM yyyy HH:mm:ss,SSS}" />
            <Field name="level" pattern="%level" />
            <Field name="simpleClassName" pattern="%C{1}" />
            <Field name="className" pattern="%C" />
            <Field name="server" pattern="%host" />
            <Field name="server.fqdn" pattern="%host{fqdn}" />
            
            <!-- This is a static field -->
            <Field name="fieldName2" literal="fieldValue2" />
             
            <!-- This is a field using MDC -->
            <Field name="mdcField2" mdc="mdcField2" /> 
            <DynamicMdcFields regex="mdc.*" />
            <DynamicMdcFields regex="(mdc|MDC)fields" />
            <DynamicMdcFieldType regex="my_field.*" type="String" />
        </Gelf>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="gelf" />
        </Root>
    </Loggers>
</Configuration>    

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

<custom-handler name="GelfLogger" class="biz.paluch.logging.gelf.jboss7.JBoss7GelfLogHandler" module="biz.paluch.logging">
    <level name="INFO" />
    <properties>
        <property name="host" value="udp:localhost" />
        <property name="port" value="12201" />
        <property name="version" value="1.1" />
        <property name="facility" value="java-test" />
        <property name="extractStackTrace" value="true" />
        <property name="filterStackTrace" value="true" />
        <property name="mdcProfiling" value="true" />
        <property name="timestampPattern" value="yyyy-MM-dd HH:mm:ss,SSS" />
        <property name="maximumMessageSize" value="8192" />
        
        <!-- This are static fields -->
        <property name="additionalFields" value="fieldName1=fieldValue1,fieldName2=fieldValue2" />
        <!-- Optional: Specify field types -->
        <property name="additionalFieldTypes" value="fieldName1=String,fieldName2=Double,fieldName3=Long" />
        
        <!-- This are fields using MDC -->
        <property name="mdcFields" value="mdcField1,mdcField2" />
        <property name="dynamicMdcFields" value="mdc.*,(mdc|MDC)fields" />
        <property name="dynamicMdcFieldTypes" value="my_field.*=String,business\..*\.field=double" />
        <property name="includeFullMdc" value="true" />
    </properties>
</custom-handler>

...

<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="FILE"/>
        <handler name="CONSOLE"/>
        <handler name="GelfLogger"/>
    </handlers>
</root-logger>

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

<custom-handler name="GelfLogger" class="biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler" module="biz.paluch.logging">
    <level name="INFO" />
    <properties>
        <property name="host" value="udp:localhost" />
        <property name="port" value="12201" />
        <property name="version" value="1.1" />
        <property name="facility" value="java-test" />
        <property name="extractStackTrace" value="true" />
        <property name="filterStackTrace" value="true" />
        <property name="mdcProfiling" value="true" />
        <property name="timestampPattern" value="yyyy-MM-dd HH:mm:ss,SSS" />
        <property name="maximumMessageSize" value="8192" />
        
        <!-- This are static fields -->
        <property name="additionalFields" value="fieldName1=fieldValue1,fieldName2=fieldValue2" />
        <!-- Optional: Specify field types -->
        <property name="additionalFieldTypes" value="fieldName1=String,fieldName2=Double,fieldName3=Long" />
        
        <!-- This are fields using MDC -->
        <property name="mdcFields" value="mdcField1,mdcField2" />
        <property name="dynamicMdcFields" value="mdc.*,(mdc|MDC)fields" />
        <property name="dynamicMdcFieldTypes" value="my_field.*=String,business\..*\.field=double" />
        <property name="includeFullMdc" value="true" />
    </properties>
</custom-handler>

...

<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="FILE"/>
        <handler name="CONSOLE"/>
        <handler name="GelfLogger"/>
    </handlers>
</root-logger>

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:

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:

<!DOCTYPE configuration>

<configuration>
    <contextName>test</contextName>
    <jmxConfigurator/>

    <appender name="gelf" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
        <host>udp:localhost</host>
        <port>12201</port>
        <version>1.1</version>
        <facility>java-test</facility>
        <extractStackTrace>true</extractStackTrace>
        <filterStackTrace>true</filterStackTrace>
        <mdcProfiling>true</mdcProfiling>
        <timestampPattern>yyyy-MM-dd HH:mm:ss,SSS</timestampPattern>
        <maximumMessageSize>8192</maximumMessageSize>
        
        <!-- This are static fields -->
        <additionalFields>fieldName1=fieldValue1,fieldName2=fieldValue2</additionalFields>
        <!-- Optional: Specify field types -->
        <additionalFieldTypes>fieldName1=String,fieldName2=Double,fieldName3=Long</additionalFieldTypes>
        
        <!-- This are fields using MDC -->
        <mdcFields>mdcField1,mdcField2</mdcFields>
        <dynamicMdcFields>mdc.*,(mdc|MDC)fields</dynamicMdcFields>
        <dynamicMdcFieldTypes>my_field.*=String,business\..*\.field=double</dynamicMdcFieldTypes>
        <includeFullMdc>true</includeFullMdc>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="gelf" />
    </root>
</configuration>

License

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

More Repositories

1

CleanArchitecture

CleanArchitecture Example
Java
227
star
2

spring-boot-virtual-threads-experiment

Project Loom Experiment using Spring Boot, Spring WebMVC, and Postgres
Java
110
star
3

spring-cloud-vault-config-samples

Examples for Spring Vault and Spring Cloud Vault Config
Java
93
star
4

microbenchmark-runner

JUnit extensions to launch JMH benchmarks from your IDE during development
Java
79
star
5

testing-with-spring-boot

Repository that explains how to test applications with Spring Boot
Java
52
star
6

reactive-spring

Project Reactor 3.3, Spring Framework 5.2, Spring Data 2.2
Java
48
star
7

spinach

Scalable Java Disque client
Java
34
star
8

redis-stream-demo

Demo for Redis Streams
Java
33
star
9

atsoundtrack

IntelliJ IDEA Plugin providing @soundtrack
Java
33
star
10

r2dbc-postgres-notification-example

Example application to produce and listen to Postgres notifications
Java
21
star
11

iot-distancemeter

Transmit sonic sensor data using RaspberryPi/Logstash/MQTT/Python
Python
21
star
12

rest-api-test

Demo for how to test a REST API with JUnit and RESTEasy 3.0
Java
13
star
13

enigma4j

Enigma βš™οΈβš™οΈβš™οΈ Emulator for Java β˜•
Java
12
star
14

reactive-tx-masterclass

Repository explaining Imperative and Reactive Transactions
Java
8
star
15

my-little-keller

App to manage grocery stock πŸπŸ‡πŸ₯«πŸ¬
Python
7
star
16

r2dbc-examples

Examples for using R2DBC and R2DBC with Spring
Java
7
star
17

Public

Public Git Repo
Java
6
star
18

loom-playground

Project Loom Playground Repository
Java
6
star
19

rename-to-main

Renames the master branch of GitHub repositories to main
Ruby
6
star
20

reactive-coding-workshop

JavaLand 2017 Reactive Coding Workshop with Spring Boot
HTML
5
star
21

under-the-hood-reactive

Reactive Drivers Showcase
Java
4
star
22

heckenlights

Java
4
star
23

remote-mocking

Remote mocking framework for integration testing
Java
4
star
24

reusing-gzip-streams

Java
4
star
25

configurator-maven-plugin

Home of the configurator-maven-plugin.
Java
3
star
26

spring-boot-r2dbc

Moved to https://github.com/spring-projects-experimental/spring-boot-r2dbc
Java
3
star
27

jee-commons

Java
3
star
28

mongo-shardgen

Shell
2
star
29

debuggable-selenide

Debuggable Selenide test sampler
Java
2
star
30

akka-actor-statistics

Pulls statistics (mailbox sizes/processing times) from Akka Actors
Java
2
star
31

reactive-vs-imperative

Java
2
star
32

redis-intro

Introduction to Java Redis Clients
Java
2
star
33

distributed-web-sessions

Example of distributed Java Web Sessions backed by MongoDB (without adding custom classes to Tomcat)
Scala
2
star
34

VoxxedDaysBucharest2017

Repository containing the code of my Reactive Spring Data talk https://speakerdeck.com/mp911de/going-reactive-with-spring-data
Shell
2
star
35

central-logging-tracking-example

Example code for tracking requests in a distributed environment
Java
2
star
36

CCD

Clean Code Examples
Java
2
star
37

logcapture

Capture your Java application logs during integration test
Java
1
star
38

spring-data-examples-runner

Runner for Spring Data Examples
Shell
1
star
39

visualizr

simple graph visualizer
JavaScript
1
star
40

pixl

Display and notification device operating system
Java
1
star
41

devoxxpl-reactive-meets-data-access

Shell
1
star
42

java8-training

Code examples using Java 8
Java
1
star
43

midi-relay

Controlling ETHRLY16 via Midi
Java
1
star
44

cdi-2.0

This repository explains CDI 2.0 features using Weld 3.0.
Java
1
star
45

majug-spring-data-mongodb-deep-dive

Repository explaining Spring Data MongoDB patterns and use cases
Java
1
star
46

logstash-gelf-subsystem

Java
1
star
47

scare-os-halloween-iot

Halloween Scary Eyes Thingy
Arduino
1
star