use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.
the class FlumePersistentAppenderTest method testRFC5424Layout.
@Test
public void testRFC5424Layout() throws IOException {
final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Log4j", "Test");
EventLogger.logEvent(msg);
final Event event = primary.poll();
Assert.assertNotNull(event);
final String body = getBody(event);
Assert.assertTrue("Structured message does not contain @EID: " + body, body.contains("Test@18060"));
}
use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.
the class FlumePersistentPerf method testPerformance.
@Test
public void testPerformance() throws Exception {
final long start = System.currentTimeMillis();
final int count = 10000;
for (int i = 0; i < count; ++i) {
final StructuredDataMessage msg = new StructuredDataMessage("Test", "Test Primary " + i, "Test");
msg.put("counter", Integer.toString(i));
EventLogger.logEvent(msg);
}
final long elapsed = System.currentTimeMillis() - start;
System.out.println("Time to log " + count + " events " + elapsed + "ms");
}
use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.
the class LoggerTest method structuredData.
@Test
public void structuredData() {
ThreadContext.put("loginId", "JohnDoe");
ThreadContext.put("ipAddress", "192.168.0.120");
ThreadContext.put("locale", Locale.US.getDisplayName());
final StructuredDataMessage msg = new StructuredDataMessage("Audit@18060", "Transfer Complete", "Transfer");
msg.put("ToAccount", "123456");
msg.put("FromAccount", "123457");
msg.put("Amount", "200.00");
logger.info(MarkerManager.getMarker("EVENT"), msg);
ThreadContext.clearMap();
assertEquals(1, results.size());
assertThat("Incorrect structured data: ", results.get(0), startsWith("EVENT INFO Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete"));
}
use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.
the class RewriteAppenderTest method testFilter.
@Test
public void testFilter() {
StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service");
msg.put("Key1", "Value2");
msg.put("Key2", "Value1");
final Logger logger = LogManager.getLogger("org.apache.logging.log4j.core.Logging");
logger.debug(msg);
msg = new StructuredDataMessage("Test", "This is a test", "Service");
msg.put("Key1", "Value1");
msg.put("Key2", "Value2");
logger.trace(msg);
final List<LogEvent> list = app.getEvents();
assertTrue("Events were generated", list == null || list.isEmpty());
}
use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.
the class RewriteAppenderTest method rewriteTest.
@Test
public void rewriteTest() {
final StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service");
msg.put("Key1", "Value1");
msg.put("Key2", "Value2");
EventLogger.logEvent(msg);
final List<LogEvent> list = app.getEvents();
assertNotNull("No events generated", list);
assertTrue("Incorrect number of events. Expected 1, got " + list.size(), list.size() == 1);
final LogEvent event = list.get(0);
final Message m = event.getMessage();
assertTrue("Message is not a MapMessage", m instanceof MapMessage);
final MapMessage message = (MapMessage) m;
final Map<String, String> map = message.getData();
assertNotNull("No Map", map);
assertTrue("Incorrect number of map entries, expected 3 got " + map.size(), map.size() == 3);
final String value = map.get("Key1");
assertEquals("Apache", value);
}
Aggregations