Skip to content
Anton Yakimov edited this page Jan 18, 2016 · 10 revisions

What is GELFJ

It's very simple GELF implementation in pure Java with the log4j appender. It supports chunked messages which allows you to send large log messages (stacktraces, environment variables, additional fields, etc.) to Graylog2 Server.

How to use GELFJ

Add the following dependency section to your pom.xml:

<dependencies>
  ...
  <dependency>
    <groupId>org.graylog2</groupId>
    <artifactId>gelfj</artifactId>
    <version>1.1.12</version>
    <scope>compile</scope>
  </dependency>
  ...
</dependencies>

Examples

To send a GELF message:

GelfMessage message = new GelfMessage("Short message", "Long message", new Date(), "1");
message.setHost("origin-host");
GelfSender gelfSender = new GelfSender("localhost");
if (message.isValid()) {
   gelfSender.sendMessage(message);
}

To send a GELF message with additional fields:

GelfMessage message = new GelfMessage("Short message", "Long message", new Date(), "1");
message.setHost("origin-host");
message.addField("id", "LOLCAT").addField("_id", "typos in my closet");
GelfSender gelfSender = new GelfSender("localhost");
if (message.isValid()) {
   gelfSender.sendMessage(message);
}

Log4j appender

For Log4j configuration please refer to https://github.com/t0xa/gelfj/blob/master/README.md

Clone this wiki locally