https://github.com/graylog2/gelfclient
GELF client library for Java based on Netty 4
https://github.com/graylog2/gelfclient
Last synced: about 1 year ago
JSON representation
GELF client library for Java based on Netty 4
- Host: GitHub
- URL: https://github.com/graylog2/gelfclient
- Owner: Graylog2
- License: apache-2.0
- Created: 2014-06-06T16:01:43.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T16:45:54.000Z (about 2 years ago)
- Last Synced: 2025-03-29T22:11:17.728Z (about 1 year ago)
- Language: Java
- Homepage: https://www.graylog.org/
- Size: 521 KB
- Stars: 39
- Watchers: 24
- Forks: 20
- Open Issues: 18
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
GELF Client
===========
[](https://mvnrepository.com/artifact/org.graylog2/gelfclient)
[](https://github.com/Graylog2/gelfclient/actions/workflows/build.yml)
A Java GELF client library with support for different transports.
Available transports:
* TCP
* UDP
All default transport implementations use a queue to send messages in a
background thread to avoid blocking the calling thread until a message has
been sent. That means that the `send()` and `trySend()` methods do not
actually send the messages but add them to a queue where the background
thread will pick them up. This is important to keep in mind when it comes to
message delivery guarantees.
The library uses [Netty v4](http://netty.io/) to handle all network related
tasks and [Jackson](https://github.com/FasterXML/jackson) for JSON encoding.
## Usage
### Maven Dependency
```xml
org.graylog2
gelfclient
1.5.1
```
### Example
```java
public class Application {
public static void main(String[] args) {
final GelfConfiguration config = new GelfConfiguration(new InetSocketAddress("example.com", 12201))
.transport(GelfTransports.UDP)
.queueSize(512)
.connectTimeout(5000)
.reconnectDelay(1000)
.tcpNoDelay(true)
.sendBufferSize(32768);
final GelfTransport transport = GelfTransports.create(config);
final GelfMessageBuilder builder = new GelfMessageBuilder("", "example.com")
.level(GelfMessageLevel.INFO)
.additionalField("_foo", "bar");
boolean blocking = false;
for (int i = 0; i < 100; i++) {
final GelfMessage message = builder.message("This is message #" + i)
.additionalField("_count", i)
.build();
if (blocking) {
// Blocks until there is capacity in the queue
transport.send(message);
} else {
// Returns false if there isn't enough room in the queue
boolean enqueued = transport.trySend(message);
}
}
}
}
```
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
## License
Apache License, Version 2.0 -- http://www.apache.org/licenses/LICENSE-2.0