Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

GELF log4j Appender for http://graylog2.com server

branch: master
README
gelf4j created by Philip Stehlik - Copyright 2011
See LICENSE for license details

---

gelf4j is set out to be an easy to use log4j appender to log to graylog2 via GELF messages.

---

Build with gradle via `gradle build` from the root directory

---

Deploy by placing the gelf4j.jar file in your class path.
If you don't have Groovy 1.7.6 already in your deployment, also place the groovy-all-1.7.6.jar in your classpath.
Of course you need log4j as well. gelf4j is built against version 1.2.16.

In a future release I hope to bundle this all up in a pom or so for easier distribution.

---

Configure the log4j appender by setting the appender class as usual and maintaining the additional configurations for the appender.
The appender's class is com.pstehlik.groovy.gelf4j.appender.Gelf4JAppender

Additional configuration options:

'additionalFields'
Set as a java Collection in your config to include additional fields to send to graylog2 server.
Default: empty/no additional fields added

'facility'
Set the facility number to use.
Default: 'GELF'

'graylogServerHost'
The host name of your graylog server. Maintained as String.
Default: 'localhost'

'graylogServerPort'
The port of your graylog server. Maintained as Integer.
Default: 12201

'host'
Sets the host name that should be mentioned in the GELF message
Default: Name of the host that runs the JVM with fallback to 'unknown_host'

'logStackTraceFromMessage'
Defines if a logged Throwable should be logged with the complete stack trace or just with the info returned by
the toString() implementation on the Throwable (which is usually calling getMessage()).
This applies to messages logged by doing things like
  log.error(myException)
message logged via
  log.error("Oh... something bad happened", myException)
have the stack trace logged and you can't change that.

If you always want to have the stack trace in your logs you should set logStackTraceFromMessage to true (which is recommended).
Default: false (for backwards compatibility)

'maxChunkSize'
The amount of bytes a message chunk can contain.
Default: 8154

---

A working example of a GELF appender in a log4j.properties file would be
# GELF appender
log4j.appender.GELF=com.pstehlik.groovy.gelf4j.appender.Gelf4JAppender
log4j.appender.GELF.graylogServerHost=my.gelf.host
log4j.appender.GELF.host=www13
log4j.appender.GELF.facility=local1

# use the GELF appender. set the level to INFO.
log4j.category.com.my.class.where.i.DoLogging=INFO, GELF

---

Notes:
- The 'short_message' of the GELF messages is limited to 250 chars and just takes the first 250 chars of the log4j message. The 'full_message' contains the full log4j text.
- The appender does not layout the message according to a message layout. It sends all the fields to the graylog2 server where you can query/look at the log.
---

Something went wrong with that request. Please try again.