use of org.slf4j.ext.EventData in project logging-log4j2 by apache.
the class LoggerTest method testEventLogger.
@Test
public void testEventLogger() {
MDC.put("loginId", "JohnDoe");
MDC.put("ipAddress", "192.168.0.120");
MDC.put("locale", Locale.US.getDisplayName());
final EventData data = new EventData();
data.setEventType("Transfer");
data.setEventId("Audit@18060");
data.setMessage("Transfer Complete");
data.put("ToAccount", "123456");
data.put("FromAccount", "123457");
data.put("Amount", "200.00");
EventLogger.logEvent(data);
MDC.clear();
verify("EventLogger", "o.a.l.s.LoggerTest Transfer [Audit@18060 Amount=\"200.00\" FromAccount=\"123457\" ToAccount=\"123456\"] Transfer Complete" + Strings.LINE_SEPARATOR);
}
use of org.slf4j.ext.EventData 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