Coder Social home page Coder Social logo

gelfclient's Introduction

GELF Client

Maven Central Build Status Coverage Status

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 to handle all network related tasks and Jackson for JSON encoding.

Usage

Maven Dependency

<dependency>
  <groupId>org.graylog2</groupId>
  <artifactId>gelfclient</artifactId>
  <version>1.4.0</version>
</dependency>

Example

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

License

Apache License, Version 2.0 -- http://www.apache.org/licenses/LICENSE-2.0

gelfclient's People

Contributors

aloren avatar bernd avatar he-pin avatar joschi avatar kroepke avatar

Watchers

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