Search in sources :

Example 66 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method appenderNameIsSet.

@Test
public void appenderNameIsSet() throws Exception {
    final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    final ConsoleAppenderFactory<ILoggingEvent> appenderFactory = new ConsoleAppenderFactory<>();
    final Appender<ILoggingEvent> appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(appender.getName()).isEqualTo("async-console-appender");
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 67 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method defaultIsNotNeverBlock.

@Test
public void defaultIsNotNeverBlock() throws Exception {
    ConsoleAppenderFactory<ILoggingEvent> consoleAppenderFactory = new ConsoleAppenderFactory<>();
    // default neverBlock
    AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.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 68 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method isNotNeverBlock.

@Test
public void isNotNeverBlock() throws Exception {
    ConsoleAppenderFactory<ILoggingEvent> consoleAppenderFactory = new ConsoleAppenderFactory<>();
    consoleAppenderFactory.setNeverBlock(false);
    AsyncAppender asyncAppender = (AsyncAppender) consoleAppenderFactory.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 69 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.

the class ConsoleAppenderFactoryTest method appenderContextIsSet.

@Test
public void appenderContextIsSet() throws Exception {
    final Logger root = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
    final ConsoleAppenderFactory<ILoggingEvent> appenderFactory = new ConsoleAppenderFactory<>();
    final Appender<ILoggingEvent> appender = appenderFactory.build(root.getLoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(appender.getContext()).isEqualTo(root.getLoggerContext());
}
Also used : AsyncLoggingEventAppenderFactory(io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory) DropwizardLayoutFactory(io.dropwizard.logging.layout.DropwizardLayoutFactory) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) Test(org.junit.Test)

Example 70 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project dropwizard by dropwizard.

the class DefaultLoggingFactoryTest method canParseNewLoggerFormat.

@Test
public void canParseNewLoggerFormat() throws Exception {
    final DefaultLoggingFactory config = factory.build(new File(Resources.getResource("yaml/logging_advanced.yml").toURI()));
    assertThat(config.getLoggers()).contains(MapEntry.entry("com.example.app", new TextNode("INFO")));
    final JsonNode newApp = config.getLoggers().get("com.example.newApp");
    assertThat(newApp).isNotNull();
    final LoggerConfiguration newAppConfiguration = objectMapper.treeToValue(newApp, LoggerConfiguration.class);
    assertThat(newAppConfiguration.getLevel()).isEqualTo(Level.DEBUG);
    assertThat(newAppConfiguration.getAppenders()).hasSize(1);
    final AppenderFactory<ILoggingEvent> appenderFactory = newAppConfiguration.getAppenders().get(0);
    assertThat(appenderFactory).isInstanceOf(FileAppenderFactory.class);
    final FileAppenderFactory<ILoggingEvent> fileAppenderFactory = (FileAppenderFactory<ILoggingEvent>) appenderFactory;
    assertThat(fileAppenderFactory.getCurrentLogFilename()).isEqualTo("${new_app}.log");
    assertThat(fileAppenderFactory.getArchivedLogFilenamePattern()).isEqualTo("${new_app}-%d.log.gz");
    assertThat(fileAppenderFactory.getArchivedFileCount()).isEqualTo(5);
    assertThat(fileAppenderFactory.getBufferSize().toKilobytes()).isEqualTo(256);
    final ImmutableList<FilterFactory<ILoggingEvent>> filterFactories = fileAppenderFactory.getFilterFactories();
    assertThat(filterFactories).hasSize(2);
    assertThat(filterFactories.get(0)).isExactlyInstanceOf(TestFilterFactory.class);
    assertThat(filterFactories.get(1)).isExactlyInstanceOf(SecondTestFilterFactory.class);
    final JsonNode legacyApp = config.getLoggers().get("com.example.legacyApp");
    assertThat(legacyApp).isNotNull();
    final LoggerConfiguration legacyAppConfiguration = objectMapper.treeToValue(legacyApp, LoggerConfiguration.class);
    assertThat(legacyAppConfiguration.getLevel()).isEqualTo(Level.DEBUG);
    // We should not create additional appenders, if they are not specified
    assertThat(legacyAppConfiguration.getAppenders()).isEmpty();
}
Also used : TextNode(com.fasterxml.jackson.databind.node.TextNode) JsonNode(com.fasterxml.jackson.databind.JsonNode) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) File(java.io.File) FilterFactory(io.dropwizard.logging.filter.FilterFactory) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)121 Test (org.junit.Test)53 Logger (ch.qos.logback.classic.Logger)44 LoggerContext (ch.qos.logback.classic.LoggerContext)41 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)23 FileAppender (ch.qos.logback.core.FileAppender)21 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)18 File (java.io.File)18 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)17 Appender (ch.qos.logback.core.Appender)15 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)14 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)10 ArrayList (java.util.ArrayList)10 Logger (org.slf4j.Logger)10 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)7 LogMessage (co.cask.cdap.logging.appender.LogMessage)7 IOException (java.io.IOException)6 Query (org.apache.lucene.search.Query)6