Search in sources :

Example 26 with StructuredDataMessage

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"));
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Event(org.apache.flume.Event) AvroFlumeEvent(org.apache.flume.source.avro.AvroFlumeEvent) Test(org.junit.Test)

Example 27 with StructuredDataMessage

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");
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Test(org.junit.Test)

Example 28 with StructuredDataMessage

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"));
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) Test(org.junit.Test)

Example 29 with StructuredDataMessage

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());
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) LogEvent(org.apache.logging.log4j.core.LogEvent) EventLogger(org.apache.logging.log4j.EventLogger) Logger(org.apache.logging.log4j.Logger) Test(org.junit.Test)

Example 30 with StructuredDataMessage

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);
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) MapMessage(org.apache.logging.log4j.message.MapMessage) Message(org.apache.logging.log4j.message.Message) LogEvent(org.apache.logging.log4j.core.LogEvent) MapMessage(org.apache.logging.log4j.message.MapMessage) Test(org.junit.Test)

Aggregations

StructuredDataMessage (org.apache.logging.log4j.message.StructuredDataMessage)40 Test (org.junit.Test)32 Event (org.apache.flume.Event)12 AvroFlumeEvent (org.apache.flume.source.avro.AvroFlumeEvent)11 LogEvent (org.apache.logging.log4j.core.LogEvent)11 File (java.io.File)6 Message (org.apache.logging.log4j.message.Message)6 EventLogger (org.apache.logging.log4j.EventLogger)5 Logger (org.apache.logging.log4j.Logger)4 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)4 StatusLogger (org.apache.logging.log4j.status.StatusLogger)4 Appender (org.apache.logging.log4j.core.Appender)3 ListAppender (org.apache.logging.log4j.test.appender.ListAppender)3 Map (java.util.Map)2 Marker (org.apache.logging.log4j.Marker)2 KeyValuePair (org.apache.logging.log4j.core.util.KeyValuePair)2 MapMessage (org.apache.logging.log4j.message.MapMessage)2 HashMap (java.util.HashMap)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1