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 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());
}
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));
}
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);
}
}
Aggregations