use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class CallerInformationTest method testMethodLogger.
@Test
public void testMethodLogger() throws Exception {
final ListAppender app = context.getListAppender("Method").clear();
final Logger logger = context.getLogger("MethodLogger");
logger.info("More messages.");
logger.warn("CATASTROPHE INCOMING!");
logger.error("ZOMBIES!!!");
logger.fatal("brains~~~");
logger.info("Itchy. Tasty.");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 5, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller method name.", "testMethodLogger", message);
}
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class SequenceNumberPatternConverterTest method testSequenceIncreases.
@Test
public void testSequenceIncreases() throws Exception {
final Logger logger = ctx.getLogger();
logger.info("Message 1");
logger.info("Message 2");
logger.info("Message 3");
logger.info("Message 4");
logger.info("Message 5");
final ListAppender app = ctx.getListAppender("List");
final List<String> messages = app.getMessages();
assertThat(messages, contains("1", "2", "3", "4", "5"));
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class PatternSelectorTest method testScriptPatternSelector.
@Test
public void testScriptPatternSelector() throws Exception {
final org.apache.logging.log4j.Logger logger = LogManager.getLogger("TestScriptPatternSelector");
final org.apache.logging.log4j.Logger logger2 = LogManager.getLogger("NoLocation");
logger.traceEntry();
logger.info("Hello World");
logger2.info("No location information");
logger.traceExit();
final ListAppender app = (ListAppender) context.getRequiredAppender("List2");
assertNotNull("No ListAppender", app);
final List<String> messages = app.getMessages();
assertNotNull("No Messages", messages);
assertTrue("Incorrect number of messages. Expected 4, Actual " + messages.size() + ": " + messages, messages.size() == 4);
String expect = "[TRACE] TestScriptPatternSelector ====== " + "o.a.l.l.c.PatternSelectorTest.testScriptPatternSelector:62 Enter ======" + Strings.LINE_SEPARATOR;
assertEquals(expect, messages.get(0));
expect = "[INFO ] TestScriptPatternSelector o.a.l.l.c.PatternSelectorTest.testScriptPatternSelector.63 " + "Hello World" + Strings.LINE_SEPARATOR;
assertEquals(expect, messages.get(1));
assertEquals("[INFO ] NoLocation No location information" + Strings.LINE_SEPARATOR, messages.get(2));
app.clear();
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class MapFilterTest method testConfig.
@Test
public void testConfig() {
final Configuration config = context.getConfiguration();
final Filter filter = config.getFilter();
assertNotNull("No MapFilter", filter);
assertTrue("Not a MapFilter", filter instanceof MapFilter);
final MapFilter mapFilter = (MapFilter) filter;
assertFalse("Should not be And filter", mapFilter.isAnd());
final Map<String, List<String>> map = mapFilter.getMap();
assertNotNull("No Map", map);
assertFalse("No elements in Map", map.isEmpty());
assertEquals("Incorrect number of elements in Map", 1, map.size());
assertTrue("Map does not contain key eventId", map.containsKey("eventId"));
assertEquals("List does not contain 2 elements", 2, map.get("eventId").size());
final Logger logger = LogManager.getLogger(MapFilterTest.class);
final Map<String, String> eventMap = new HashMap<>();
eventMap.put("eventId", "Login");
logger.debug(new MapMessage(eventMap));
final ListAppender app = context.getListAppender("LIST");
final List<String> msgs = app.getMessages();
assertNotNull("No messages", msgs);
assertFalse("No messages", msgs.isEmpty());
}
Aggregations