Search in sources :

Example 6 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent 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 7 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent 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 8 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project openhab1-addons by openhab.

the class LoggingPersistenceService method createNewAppender.

protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern(pattern);
    encoder.start();
    FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
    appender.setAppend(true);
    appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
    appender.setEncoder(encoder);
    appender.setContext(context);
    appender.start();
    return appender;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) FileAppender(ch.qos.logback.core.FileAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 9 with ILoggingEvent

use of ch.qos.logback.classic.spi.ILoggingEvent in project jackrabbit-oak by apache.

the class OperationLoggerTest method testBinaryLogger.

public void testBinaryLogger() throws Exception {
    Node node1 = testRootNode.addNode(nodeName1);
    start();
    byte[] data = "hello".getBytes();
    Binary b = superuser.getValueFactory().createBinary(new ByteArrayInputStream(data));
    node1.setProperty("foo", b);
    stop();
    boolean binaryLog = false;
    for (ILoggingEvent e : logs.list) {
        if (e.getLoggerName().startsWith(OPS_BINARY)) {
            if (e.getMessage().contains("Created binary property")) {
                assertEquals(Long.valueOf(data.length), e.getArgumentArray()[0]);
                binaryLog = true;
            }
        }
    }
    assertTrue("Did not find binary upload log", binaryLog);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) Binary(javax.jcr.Binary) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 10 with ILoggingEvent

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

the class ITFilterSupport method filterUsingWildcard.

@Test
public void filterUsingWildcard() throws Exception {
    TestAppender ta1 = registerAppender("filterUsingWildcard1", "app1");
    TestAppender ta2 = registerAppender("filterUsingWildcard2", "app2");
    //Set additivity to false to prevent other appender like CONSOLE from
    //interfering
    org.slf4j.Logger baz1 = LoggerFactory.getLogger("filterUsingWildcard1.foo.baz");
    ((ch.qos.logback.classic.Logger) baz1).setAdditive(false);
    org.slf4j.Logger baz2 = LoggerFactory.getLogger("filterUsingWildcard2.foo.baz");
    ((ch.qos.logback.classic.Logger) baz2).setAdditive(false);
    final List<String> msgs = new ArrayList<String>();
    Filter stf = new Filter<ILoggingEvent>() {

        @Override
        public FilterReply decide(ILoggingEvent event) {
            msgs.add(event.getMessage());
            return FilterReply.NEUTRAL;
        }
    };
    Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("appenders", "*");
    ServiceRegistration sr = bundleContext.registerService(Filter.class.getName(), stf, props);
    delay();
    baz1.info("baz1-1");
    baz2.info("baz2-1");
    assertEquals(2, msgs.size());
}
Also used : Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) MatchingFilter(ch.qos.logback.classic.turbo.MatchingFilter) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter) Filter(ch.qos.logback.core.filter.Filter) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)300 Test (org.junit.Test)111 Logger (ch.qos.logback.classic.Logger)90 LoggerContext (ch.qos.logback.classic.LoggerContext)85 Appender (ch.qos.logback.core.Appender)48 Test (org.junit.jupiter.api.Test)47 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)44 FileAppender (ch.qos.logback.core.FileAppender)40 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)35 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)30 File (java.io.File)26 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)22 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)21 Logger (org.slf4j.Logger)20 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)17 AsyncAppender (ch.qos.logback.classic.AsyncAppender)16 ArrayList (java.util.ArrayList)16 ListAppender (ch.qos.logback.core.read.ListAppender)15 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13