Search in sources :

Example 31 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 32 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 33 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class RoutingAppenderTest method routingTest.

@Test
public void routingTest() {
    StructuredDataMessage msg = new StructuredDataMessage("Test", "This is a test", "Service");
    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);
    msg = new StructuredDataMessage("Test", "This is a test", "Alert");
    EventLogger.logEvent(msg);
    File file = new File(ALERT_LOG_FILE);
    assertTrue("Alert file was not created", file.exists());
    msg = new StructuredDataMessage("Test", "This is a test", "Activity");
    EventLogger.logEvent(msg);
    file = new File(ACTIVITY_LOG_FILE);
    assertTrue("Activity file was not created", file.exists());
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) LogEvent(org.apache.logging.log4j.core.LogEvent) File(java.io.File) Test(org.junit.Test)

Example 34 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class LogEventFactory method getEvent.

@SuppressWarnings("unchecked")
public static <T extends AuditEvent> T getEvent(final Class<T> intrface) {
    final String eventId = NamingUtils.lowerFirst(intrface.getSimpleName());
    final StructuredDataMessage msg = new StructuredDataMessage(eventId, null, "Audit");
    return (T) Proxy.newProxyInstance(intrface.getClassLoader(), new Class<?>[] { intrface }, new AuditProxy(msg, intrface));
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage)

Example 35 with StructuredDataMessage

use of org.apache.logging.log4j.message.StructuredDataMessage in project logging-log4j2 by apache.

the class EventDataConverter method convertEvent.

public Message convertEvent(final String message, final Object[] objects, final Throwable throwable) {
    try {
        final EventData data = objects != null && objects[0] instanceof EventData ? (EventData) objects[0] : new EventData(message);
        final StructuredDataMessage msg = new StructuredDataMessage(data.getEventId(), data.getMessage(), data.getEventType());
        for (final Map.Entry<String, Object> entry : data.getEventMap().entrySet()) {
            final String key = entry.getKey();
            if (EventData.EVENT_TYPE.equals(key) || EventData.EVENT_ID.equals(key) || EventData.EVENT_MESSAGE.equals(key)) {
                continue;
            }
            msg.put(key, String.valueOf(entry.getValue()));
        }
        return msg;
    } catch (final Exception ex) {
        return new ParameterizedMessage(message, objects, throwable);
    }
}
Also used : StructuredDataMessage(org.apache.logging.log4j.message.StructuredDataMessage) ParameterizedMessage(org.apache.logging.log4j.message.ParameterizedMessage) Map(java.util.Map) EventData(org.slf4j.ext.EventData)

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