Search in sources :

Example 1 with ShortenedThrowableConverter

use of net.logstash.logback.stacktrace.ShortenedThrowableConverter in project uplace.es by Uplace.

the class LoggingConfiguration method addLogstashAppender.

private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");
    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";
    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder = new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(), jHipsterProperties.getLogging().getLogstash().getPort()));
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);
    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();
    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();
    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
Also used : LogstashEncoder(net.logstash.logback.encoder.LogstashEncoder) AsyncAppender(ch.qos.logback.classic.AsyncAppender) InetSocketAddress(java.net.InetSocketAddress) ShortenedThrowableConverter(net.logstash.logback.stacktrace.ShortenedThrowableConverter) LogstashTcpSocketAppender(net.logstash.logback.appender.LogstashTcpSocketAppender)

Aggregations

AsyncAppender (ch.qos.logback.classic.AsyncAppender)1 InetSocketAddress (java.net.InetSocketAddress)1 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)1 LogstashEncoder (net.logstash.logback.encoder.LogstashEncoder)1 ShortenedThrowableConverter (net.logstash.logback.stacktrace.ShortenedThrowableConverter)1