Search in sources :

Example 6 with LoggerContext

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

the class FileAppenderFactoryTest method isNeverBlock.

@Test
public void isNeverBlock() throws Exception {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    fileAppenderFactory.setNeverBlock(true);
    AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isNeverBlock()).isTrue();
}
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 7 with LoggerContext

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

the class FileAppenderFactoryTest method isRolling.

@Test
public void isRolling() throws Exception {
    // the method we want to test is protected, so we need to override it so we can see it
    FileAppenderFactory fileAppenderFactory = new FileAppenderFactory<ILoggingEvent>() {

        @Override
        public FileAppender<ILoggingEvent> buildAppender(LoggerContext context) {
            return super.buildAppender(context);
        }
    };
    fileAppenderFactory.setCurrentLogFilename(folder.newFile("logfile.log").toString());
    fileAppenderFactory.setArchive(true);
    fileAppenderFactory.setArchivedLogFilenamePattern(folder.newFile("example-%d.log.gz").toString());
    assertThat(fileAppenderFactory.buildAppender(new LoggerContext())).isInstanceOf(RollingFileAppender.class);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 8 with LoggerContext

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

the class FileAppenderFactoryTest method isValidForInfiniteRolledFiles.

@Test
public void isValidForInfiniteRolledFiles() throws Exception {
    FileAppenderFactory fileAppenderFactory = new FileAppenderFactory();
    fileAppenderFactory.setCurrentLogFilename(folder.newFile("logfile.log").toString());
    fileAppenderFactory.setArchivedFileCount(0);
    fileAppenderFactory.setArchivedLogFilenamePattern(folder.newFile("example-%d.log.gz").toString());
    ImmutableList<String> errors = ConstraintViolations.format(validator.validate(fileAppenderFactory));
    assertThat(errors).isEmpty();
    assertThat(fileAppenderFactory.buildAppender(new LoggerContext())).isNotNull();
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 9 with LoggerContext

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

the class SyslogAppenderFactoryTest method stackTracePatternCanBeSet.

@Test
public void stackTracePatternCanBeSet() throws Exception {
    final SyslogAppenderFactory syslogAppenderFactory = new SyslogAppenderFactory();
    syslogAppenderFactory.setStackTracePrefix("--->");
    final AsyncAppender wrapper = (AsyncAppender) syslogAppenderFactory.build(new LoggerContext(), "MyApplication", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(((SyslogAppender) wrapper.getAppender("syslog-appender")).getStackTracePattern()).isEqualTo("--->");
}
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 10 with LoggerContext

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

the class DefaultLoggingFactoryPrintErrorMessagesTest method testWhenUsingDefaultConstructor_StaticILoggerFactoryIsSet.

@Test
public void testWhenUsingDefaultConstructor_StaticILoggerFactoryIsSet() throws Exception {
    LoggerContext loggerContext = new DefaultLoggingFactory().getLoggerContext();
    assertThat(loggerContext).isSameAs(LoggerFactory.getILoggerFactory());
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)200 Test (org.junit.Test)133 Logger (ch.qos.logback.classic.Logger)39 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)39 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)21 FileAppender (ch.qos.logback.core.FileAppender)19 File (java.io.File)18 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)15 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)15 Appender (ch.qos.logback.core.Appender)14 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)13 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 JoranException (ch.qos.logback.core.joran.spi.JoranException)10 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 ArrayList (java.util.ArrayList)6