org.graylog2.gelfclient.GelfConfiguration Java Examples

The following examples show how to use org.graylog2.gelfclient.GelfConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractGelfTransportTest.java    From gelfclient with Apache License 2.0 6 votes vote down vote up
@Test
public void testThreads() throws Exception {
    final int threads = 23;
    final GelfConfiguration configuration = new GelfConfiguration().threads(threads);
    final AbstractGelfTransport transport = new AbstractGelfTransport(configuration) {
        @Override
        protected void createBootstrap(EventLoopGroup workerGroup) {
            final NioEventLoopGroup eventLoopGroup = (NioEventLoopGroup) workerGroup;
            assertEquals(threads, eventLoopGroup.executorCount());
        }

        @Override
        public void flushAndStopSynchronously(int waitDuration, TimeUnit timeUnit, int retries) {
            super.flushAndStopSynchronously(waitDuration, timeUnit, retries);
        }
    };
    transport.stop();
}
 
Example #2
Source File: GelfAppender.java    From logback-gelf-appender with Apache License 2.0 5 votes vote down vote up
private GelfConfiguration getGelfConfiguration() {

        final InetSocketAddress serverAddress = new InetSocketAddress(server, port);
        final GelfTransports gelfProtocol = GelfTransports.valueOf(protocol().toUpperCase());

        return new GelfConfiguration(serverAddress).transport(gelfProtocol)
            .queueSize(queueSize)
            .connectTimeout(connectTimeout)
            .reconnectDelay(reconnectDelay)
            .sendBufferSize(sendBufferSize)
            .tcpNoDelay(tcpNoDelay)
            .tcpKeepAlive(tcpKeepAlive);
    }
 
Example #3
Source File: AbstractGelfTransport.java    From gelfclient with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new GELF transport with the given configuration and {@link java.util.concurrent.BlockingQueue}.
 *
 * @param config the client configuration
 * @param queue  the {@link BlockingQueue} used to buffer GELF messages
 */
public AbstractGelfTransport(final GelfConfiguration config, final BlockingQueue<GelfMessage> queue) {
    this.config = config;
    this.queue = queue;
    this.workerGroup = new NioEventLoopGroup(config.getThreads(), new DefaultThreadFactory(getClass(), true));
    this.senderThreadReference = new AtomicReference<>();
    createBootstrap(workerGroup);
}
 
Example #4
Source File: GelfAppender.java    From log4j2-gelf with Apache License 2.0 5 votes vote down vote up
protected GelfAppender(final String name,
                       final Layout<? extends Serializable> layout,
                       final Filter filter,
                       final boolean ignoreExceptions,
                       final GelfConfiguration gelfConfiguration,
                       final String hostName,
                       final boolean includeSource,
                       final boolean includeThreadContext,
                       final boolean includeStackTrace,
                       final KeyValuePair[] additionalFields,
                       final boolean includeExceptionCause) {
    super(name, filter, layout, ignoreExceptions);
    this.gelfConfiguration = gelfConfiguration;
    this.hostName = hostName;
    this.includeSource = includeSource;
    this.includeThreadContext = includeThreadContext;
    this.includeStackTrace = includeStackTrace;
    this.includeExceptionCause = includeExceptionCause;

    if (null != additionalFields) {
        this.additionalFields = new HashMap<>();
        for (KeyValuePair pair : additionalFields) {
            this.additionalFields.put(pair.getKey(), pair.getValue());
        }
    } else {
        this.additionalFields = Collections.emptyMap();
    }
}
 
Example #5
Source File: Graylog2Plugin.java    From play2-graylog2 with Apache License 2.0 5 votes vote down vote up
public Graylog2Plugin(Application app) {
    final Configuration config = app.configuration();

    accessLogEnabled = config.getBoolean("graylog2.appender.send-access-log", false);
    queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
    reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
    connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
    isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
    sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used
    try {
        canonicalHostName = config.getString("graylog2.appender.sourcehost", InetAddress.getLocalHost().getCanonicalHostName());
    } catch (UnknownHostException e) {
        canonicalHostName = "localhost";
        log.error("Unable to resolve canonical localhost name. " +
                "Please set it manually via graylog2.appender.sourcehost or fix your lookup service, falling back to {}", canonicalHostName);
    }
    // TODO make this a list and dynamically accessible from the application
    final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
    final String protocol = config.getString("graylog2.appender.protocol", "tcp");

    final HostAndPort hostAndPort = HostAndPort.fromString(hostString);

    final GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());

    final GelfConfiguration gelfConfiguration = new GelfConfiguration(hostAndPort.getHostText(), hostAndPort.getPort())
            .transport(gelfTransport)
            .reconnectDelay(reconnectInterval.intValue())
            .queueSize(queueCapacity)
            .connectTimeout(connectTimeout.intValue())
            .tcpNoDelay(isTcpNoDelay)
            .sendBufferSize(sendBufferSize);

    this.transport = GelfTransports.create(gelfConfiguration);

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);

    gelfAppender = new GelfclientAppender(transport, getLocalHostName());
    gelfAppender.setContext(lc);
}
 
Example #6
Source File: GelfUdpTransport.java    From gelfclient with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new UDP GELF transport.
 *
 * @param config the GELF client configuration
 */
public GelfUdpTransport(final GelfConfiguration config) {
    super(config);
}
 
Example #7
Source File: GelfTcpTransport.java    From gelfclient with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new TCP GELF transport.
 *
 * @param config the GELF client configuration
 */
public GelfTcpTransport(GelfConfiguration config) {
    super(config);
}
 
Example #8
Source File: AbstractGelfTransport.java    From gelfclient with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new GELF transport with the given configuration.
 *
 * @param config the client configuration
 */
public AbstractGelfTransport(final GelfConfiguration config) {
    this(config, new LinkedBlockingQueue<GelfMessage>(config.getQueueSize()));

}