Search in sources :

Example 61 with LoggerContext

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

the class ConsoleAppenderFactoryTest method includesCallerData.

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

Example 62 with LoggerContext

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

the class ConsoleAppenderFactoryTest method isNeverBlock.

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

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

the class LogbackAccessRequestLogFactory method build.

@Override
public RequestLog build(String name) {
    final Logger logger = (Logger) LoggerFactory.getLogger("http.request");
    logger.setAdditive(false);
    final LoggerContext context = logger.getLoggerContext();
    final LogbackAccessRequestLog requestLog = new LogbackAccessRequestLog();
    final LevelFilterFactory<IAccessEvent> levelFilterFactory = new NullLevelFilterFactory<>();
    final AsyncAppenderFactory<IAccessEvent> asyncAppenderFactory = new AsyncAccessEventAppenderFactory();
    final LayoutFactory<IAccessEvent> layoutFactory = new LogbackAccessRequestLayoutFactory();
    for (AppenderFactory<IAccessEvent> output : appenders) {
        requestLog.addAppender(output.build(context, name, layoutFactory, levelFilterFactory, asyncAppenderFactory));
    }
    return requestLog;
}
Also used : LogbackAccessRequestLayoutFactory(io.dropwizard.request.logging.layout.LogbackAccessRequestLayoutFactory) AsyncAccessEventAppenderFactory(io.dropwizard.request.logging.async.AsyncAccessEventAppenderFactory) IAccessEvent(ch.qos.logback.access.spi.IAccessEvent) NullLevelFilterFactory(io.dropwizard.logging.filter.NullLevelFilterFactory) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 64 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 65 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)

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