use of org.apache.log4j.ListAppender in project logging-log4j2 by apache.
the class AsyncAppenderTest method testAsyncXml.
@Test
public void testAsyncXml() throws Exception {
try (final LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/log4j1-async.xml")) {
final Logger logger = LogManager.getLogger("test");
logger.debug("This is a test of the root logger");
Thread.sleep(50);
final Configuration configuration = loggerContext.getConfiguration();
final Map<String, Appender> appenders = configuration.getAppenders();
ListAppender messageAppender = null;
for (final Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("list")) {
messageAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
}
}
assertNotNull("No Message Appender", messageAppender);
final List<String> messages = messageAppender.getMessages();
assertTrue("No messages", messages != null && messages.size() > 0);
}
}
use of org.apache.log4j.ListAppender in project logging-log4j2 by apache.
the class MapRewriteAppenderTest method testRewrite.
@Test
public void testRewrite() throws Exception {
Logger logger = LogManager.getLogger("test");
Map<String, String> map = new HashMap<>();
map.put("message", "This is a test");
map.put("hello", "world");
logger.debug(map);
LoggerContext context = (LoggerContext) org.apache.logging.log4j.LogManager.getContext(false);
Configuration configuration = context.getConfiguration();
Map<String, Appender> appenders = configuration.getAppenders();
ListAppender eventAppender = null;
for (Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("events")) {
eventAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
}
}
assertNotNull("No Event Appender", eventAppender);
List<LoggingEvent> events = eventAppender.getEvents();
assertTrue("No events", events != null && events.size() > 0);
assertNotNull("No properties in the event", events.get(0).getProperties());
assertTrue("Key was not inserted", events.get(0).getProperties().containsKey("hello"));
assertEquals("Key value is incorrect", "world", events.get(0).getProperties().get("hello"));
}
use of org.apache.log4j.ListAppender in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testListAppender.
@Test
public void testListAppender() throws Exception {
try (LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/log4j1-list.properties")) {
final Logger logger = LogManager.getLogger("test");
logger.debug("This is a test of the root logger");
final Configuration configuration = loggerContext.getConfiguration();
final Map<String, Appender> appenders = configuration.getAppenders();
ListAppender eventAppender = null;
ListAppender messageAppender = null;
for (final Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("list")) {
messageAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
} else if (entry.getKey().equals("events")) {
eventAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
}
}
assertNotNull("No Event Appender", eventAppender);
assertNotNull("No Message Appender", messageAppender);
final List<LoggingEvent> events = eventAppender.getEvents();
assertTrue("No events", events != null && events.size() > 0);
final List<String> messages = messageAppender.getMessages();
assertTrue("No messages", messages != null && messages.size() > 0);
}
}
use of org.apache.log4j.ListAppender in project logging-log4j2 by apache.
the class XmlConfigurationTest method testListAppender.
@Test
public void testListAppender() throws Exception {
LoggerContext loggerContext = configure("target/test-classes/log4j1-list.xml");
Logger logger = LogManager.getLogger("test");
logger.debug("This is a test of the root logger");
Configuration configuration = loggerContext.getConfiguration();
Map<String, Appender> appenders = configuration.getAppenders();
ListAppender eventAppender = null;
ListAppender messageAppender = null;
for (Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("list")) {
messageAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
} else if (entry.getKey().equals("events")) {
eventAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
}
}
assertNotNull("No Event Appender", eventAppender);
assertNotNull("No Message Appender", messageAppender);
List<LoggingEvent> events = eventAppender.getEvents();
assertTrue("No events", events != null && events.size() > 0);
List<String> messages = messageAppender.getMessages();
assertTrue("No messages", messages != null && messages.size() > 0);
}
use of org.apache.log4j.ListAppender in project logging-log4j2 by apache.
the class AsyncAppenderTest method testAsyncProperties.
@Test
public void testAsyncProperties() throws Exception {
try (final LoggerContext loggerContext = TestConfigurator.configure("target/test-classes/log4j1-async.properties")) {
final Logger logger = LogManager.getLogger("test");
logger.debug("This is a test of the root logger");
Thread.sleep(50);
final Configuration configuration = loggerContext.getConfiguration();
final Map<String, Appender> appenders = configuration.getAppenders();
ListAppender messageAppender = null;
for (final Map.Entry<String, Appender> entry : appenders.entrySet()) {
if (entry.getKey().equals("list")) {
messageAppender = (ListAppender) ((AppenderAdapter.Adapter) entry.getValue()).getAppender();
}
}
assertNotNull("No Message Appender", messageAppender);
final List<String> messages = messageAppender.getMessages();
assertTrue("No messages", messages != null && messages.size() > 0);
}
}
Aggregations