use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class CsvParameterLayoutTest method testLogJsonArgument.
@Test
public void testLogJsonArgument() throws InterruptedException {
final ListAppender appender = (ListAppender) init.getAppender("List");
appender.countDownLatch = new CountDownLatch(4);
appender.clear();
final Logger logger = (Logger) LogManager.getRootLogger();
final String json = "{\"id\":10,\"name\":\"Alice\"}";
logger.error("log:{}", json);
// wait until background thread finished processing
final int msgCount = 1;
if (appender.getMessages().size() < msgCount) {
appender.countDownLatch.await(5, TimeUnit.SECONDS);
}
assertEquals("Background thread did not finish processing: msg count", msgCount, appender.getMessages().size());
// don't stop appender until background thread is done
appender.stop();
final List<String> list = appender.getMessages();
final String eventStr = list.get(0).toString();
Assert.assertTrue(eventStr, eventStr.contains(json));
}
use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class Log4j2SpringBootInitTest method testEnvironment.
@Test
public void testEnvironment() {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
ListAppender app = context.getConfiguration().getAppender("Out");
assertNotNull(app);
assertEquals(1, app.getMessages().size());
assertEquals("Started: log4j-spring-boot", app.getMessages().get(0));
}
use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class CatchingTagTest 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.CatchingTagTest " + 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 SpringProfileTest method prodTest.
@Test
public void prodTest() {
env.setActiveProfiles("prod");
loggerContext.setConfigLocation(new File(CONFIG).toURI());
assertNotNull(loggerContext);
Appender app = loggerContext.getConfiguration().getAppender("Out");
assertNotNull(app);
assertTrue(app instanceof ListAppender);
}
use of org.apache.logging.log4j.core.test.appender.ListAppender in project logging-log4j2 by apache.
the class RoutesScriptAppenderTest 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);
return (ListAppender) appenderControl.getAppender();
}
Aggregations