Search in sources :

Example 66 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 67 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 68 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)

Example 69 with LoggerContext

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

the class FileAppenderFactoryTest method testCurrentLogFileNameIsEmptyAndAppenderUsesArchivedNameInstead.

@Test
public void testCurrentLogFileNameIsEmptyAndAppenderUsesArchivedNameInstead() throws Exception {
    final FileAppenderFactory<ILoggingEvent> appenderFactory = new FileAppenderFactory<>();
    appenderFactory.setArchivedLogFilenamePattern(folder.newFile("test-archived-name-%d.log").toString());
    final FileAppender<ILoggingEvent> rollingAppender = appenderFactory.buildAppender(new LoggerContext());
    final String file = rollingAppender.getFile();
    final String dateSuffix = LocalDateTime.now().format(DateTimeFormatter.ofPattern("YYYY-MM-dd"));
    final String name = Files.getNameWithoutExtension(file);
    Assert.assertEquals("test-archived-name-" + dateSuffix, name);
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 70 with LoggerContext

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

the class FileAppenderFactoryTest method includesCallerData.

@Test
public void includesCallerData() {
    FileAppenderFactory<ILoggingEvent> fileAppenderFactory = new FileAppenderFactory<>();
    fileAppenderFactory.setArchive(false);
    AsyncAppender asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isIncludeCallerData()).isFalse();
    fileAppenderFactory.setIncludeCallerData(true);
    asyncAppender = (AsyncAppender) fileAppenderFactory.build(new LoggerContext(), "test", new DropwizardLayoutFactory(), new NullLevelFilterFactory<>(), new AsyncLoggingEventAppenderFactory());
    assertThat(asyncAppender.isIncludeCallerData()).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)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)216 Test (org.junit.Test)134 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)43 Logger (ch.qos.logback.classic.Logger)41 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)26 FileAppender (ch.qos.logback.core.FileAppender)22 File (java.io.File)21 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)19 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)16 Appender (ch.qos.logback.core.Appender)14 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)14 JoranException (ch.qos.logback.core.joran.spi.JoranException)14 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)13 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 Logger (org.slf4j.Logger)10 IOException (java.io.IOException)8 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)7 URL (java.net.URL)7