Skip to content

pstehlik/gelf4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

'additionalFieldsJson'
Set as a json string of name/value pairs in your config to include additional fields to send to graylog2 server.
Default: empty/no additional fields added
Example: log4j.appender.GELF.additionalFieldsJson={"server_name":"localhost"}

'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

'mdcFields'
A list of fields to read from log4j MDC and append to the additional fields

'mdcFieldsJson'
Set as a json string of a list of fields to read from log4j MDC and append to the additional fields
Default: empty/no additional fields added
Example: log4j.appender.GELF.mdcFieldsJson=["server_name","user_name"]

---

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.
---

Releases

No releases published

Packages

No packages published