-
Notifications
You must be signed in to change notification settings - Fork 115
Home
Anton Yakimov edited this page Jan 18, 2016
·
10 revisions
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.
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>
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);
}
For Log4j configuration please refer to https://github.com/t0xa/gelfj/blob/master/README.md