Search in sources :

Example 11 with ListAppender

use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.

the class LoggingMessageTagSupportTest method verify.

private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.LoggingMessageTagSupportTest " + expected, events.get(0));
    } finally {
        listApp.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender)

Example 12 with ListAppender

use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.

the class EnterTagTest method verify.

private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.EnterTagTest " + expected, events.get(0));
    } finally {
        listApp.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender)

Example 13 with ListAppender

use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.

the class ExitTagTest method verify.

private void verify(final String expected) {
    final ListAppender listApp = context.getListAppender("List");
    final List<String> events = listApp.getMessages();
    try {
        assertEquals("Incorrect number of messages.", 1, events.size());
        assertEquals("Incorrect message.", "o.a.l.l.t.ExitTagTest " + expected, events.get(0));
    } finally {
        listApp.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender)

Example 14 with ListAppender

use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.

the class AbstractScriptFilterTest method testGroovyFilter.

@Test
public void testGroovyFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestGroovyFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    try {
        final List<String> messages = app.getMessages();
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 15 with ListAppender

use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.

the class AbstractScriptFilterTest method testJavascriptFilter.

@Test
public void testJavascriptFilter() throws Exception {
    final Logger logger = LogManager.getLogger("TestJavaScriptFilter");
    logger.traceEntry();
    logger.info("This should not be logged");
    ThreadContext.put("UserId", "JohnDoe");
    logger.info("This should be logged");
    ThreadContext.clearMap();
    final ListAppender app = getContext().getListAppender("List");
    final List<String> messages = app.getMessages();
    try {
        assertNotNull("No Messages", messages);
        assertTrue("Incorrect number of messages. Expected 2, Actual " + messages.size(), messages.size() == 2);
    } finally {
        app.clear();
    }
}
Also used : ListAppender(org.apache.logging.log4j.test.appender.ListAppender) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Aggregations

ListAppender (org.apache.logging.log4j.test.appender.ListAppender)64 Test (org.junit.Test)46 Appender (org.apache.logging.log4j.core.Appender)17 Logger (org.apache.logging.log4j.Logger)8 LogEvent (org.apache.logging.log4j.core.LogEvent)6 Configuration (org.apache.logging.log4j.core.config.Configuration)5 AbstractLogger (org.apache.logging.log4j.spi.AbstractLogger)5 Marker (org.apache.logging.log4j.Marker)4 Logger (org.apache.logging.log4j.core.Logger)4 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)4 StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Logger (java.util.logging.Logger)2 Log (org.apache.commons.logging.Log)2 AppenderControl (org.apache.logging.log4j.core.config.AppenderControl)2 Logger (org.slf4j.Logger)2 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1