use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class CallerInformationTest method testClassLogger.
@Test
public void testClassLogger() throws Exception {
final ListAppender app = ctx.getListAppender("Class").clear();
final Log logger = LogFactory.getLog("ClassLogger");
logger.info("Ignored message contents.");
logger.warn("Verifying the caller class is still correct.");
logger.error("Hopefully nobody breaks me!");
final List<String> messages = app.getMessages();
assertEquals("Incorrect number of messages.", 3, messages.size());
for (final String message : messages) {
assertEquals("Incorrect caller class name.", this.getClass().getName(), message);
}
}
use of org.apache.logging.log4j.core.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();
}
}
use of org.apache.logging.log4j.core.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();
}
}
use of org.apache.logging.log4j.core.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();
}
}
use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class CategoryTest method testClassName.
@Test
public void testClassName() {
final Category category = Category.getInstance("TestCategory");
final Layout<String> layout = PatternLayout.newBuilder().setPattern("%d %p %C{1.} [%t] %m%n").build();
final ListAppender appender = new ListAppender("List2", null, layout, false, false);
appender.start();
category.setAdditivity(false);
((org.apache.logging.log4j.core.Logger) category.getLogger()).addAppender(appender);
category.error("Test Message");
final List<String> msgs = appender.getMessages();
assertTrue("Incorrect number of messages. Expected 1 got " + msgs.size(), msgs.size() == 1);
final String msg = msgs.get(0);
appender.clear();
final String threadName = Thread.currentThread().getName();
final String expected = "ERROR o.a.l.CategoryTest [" + threadName + "] Test Message" + Strings.LINE_SEPARATOR;
assertTrue("Incorrect message " + Strings.dquote(msg) + " expected " + Strings.dquote(expected), msg.endsWith(expected));
}
Aggregations