Giter Club home page Giter Club logo

gelf4j's Introduction

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

gelf4j's People

Contributors

pstehlik avatar livingtocode avatar jsteiger-taulia avatar michaeldai-taulia avatar safetytrick avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.