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 = ctx.getListAppender("Method").clear();
final Log logger = LogFactory.getLog("MethodLogger");
logger.info("More messages.");
logger.warn("CATASTROPHE INCOMING!");
logger.error("ZOMBIES!!!");
logger.warn("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 LoggerTest method verify.
private void verify(final String name, final String expected) {
final ListAppender listApp = context.getListAppender(name);
final List<String> events = listApp.getMessages();
assertThat(events, hasSize(1));
final String actual = events.get(0);
assertThat(actual, equalTo(expected));
listApp.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());
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class DefaultRouteScriptAppenderTest method getListAppender.
private ListAppender getListAppender() {
final String key = "Service2";
final RoutingAppender routingAppender = getRoutingAppender();
Assert.assertTrue(routingAppender.isStarted());
final Map<String, AppenderControl> appenders = routingAppender.getAppenders();
final AppenderControl appenderControl = appenders.get(key);
assertNotNull("No appender control generated for '" + key + "'; appenders = " + appenders, appenderControl);
final ListAppender listAppender = (ListAppender) appenderControl.getAppender();
return listAppender;
}
use of org.apache.logging.log4j.test.appender.ListAppender in project logging-log4j2 by apache.
the class DefaultRouteScriptAppenderTest method logAndCheck.
private void logAndCheck() {
final Marker marker = MarkerManager.getMarker("HEXDUMP");
final Logger logger = loggerContextRule.getLogger(DefaultRouteScriptAppenderTest.class);
logger.error("Hello");
final ListAppender listAppender = getListAppender();
final List<LogEvent> list = listAppender.getEvents();
assertNotNull("No events generated", list);
assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
logger.error("World");
assertTrue("Incorrect number of events. Expected 2, got " + list.size(), list.size() == 2);
logger.error(marker, "DEADBEEF");
assertTrue("Incorrect number of events. Expected 3, got " + list.size(), list.size() == 3);
}
Aggregations