Search in sources :

Example 11 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class FileAppenderFactoryTest method isNotNeverBlock.

@Test
public void isNotNeverBlock() throws Exception {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    fileAppenderFactory.setNeverBlock(false);
    AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isNeverBlock()).isFalse();
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 12 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender in project dropwizard by dropwizard.

the class SyslogAppenderFactoryTest method patternIncludesAppNameAndPid.

@Test
public void patternIncludesAppNameAndPid() throws Exception {
    final AsyncAppender wrapper = (AsyncAppender) new SyslogAppenderFactory().build(new LoggerContext(), "MyApplication", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getSuffixPattern()).matches("^MyApplication\\[\\d+\\].+");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) AsyncAppender(ch.qos.logback.classic.AsyncAppender) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) SyslogAppender(ch.qos.logback.classic.net.SyslogAppender) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 13 with AsyncAppender

use of ch.qos.logback.classic.AsyncAppender 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)13 LoggerContext (ch.qos.logback.classic.LoggerContext)11 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)11 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 Test (org.junit.Test)11 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)10 SyslogAppender (ch.qos.logback.classic.net.SyslogAppender)2 Logger (ch.qos.logback.classic.Logger)1 Appender (ch.qos.logback.core.Appender)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 FileSize (ch.qos.logback.core.util.FileSize)1 InstrumentedAppender (com.codahale.metrics.logback.InstrumentedAppender)1 Field (java.lang.reflect.Field)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