java类org.slf4j.ext.EventData的实例源码

EventLoggerTest.java 文件源码 项目:bartleby 阅读 25 收藏 0 点赞 0 评论 0
public void testEventLogger() {
    EventData data[] = new EventData[2];
    data[0] = new EventData();
    data[0].setEventType("Login");
    data[0].setEventId("1");
    data[0].setEventDateTime(new Date());
    data[0].put("Userid", "TestUser");
    EventLogger.logEvent(data[0]);

    data[1] = new EventData();
    data[1].setEventType("Update");
    data[1].setEventId("2");
    data[1].setEventDateTime(new Date());
    data[1].put("FileName", "/etc/hosts");
    EventLogger.logEvent(data[1]);

    assertEquals(2, listAppender.list.size());
    for (int i = 0; i < 2; ++i) {
        LoggingEvent event = listAppender.list.get(i);
        verify(event, data[i].toXML());
        LocationInfo li = event.getLocationInformation();
        assertEquals(this.getClass().getName(), li.getClassName());
        assertEquals(event.getMDC("hostname"), "localhost");
    }
}
EventDataConverter.java 文件源码 项目:log4j2 阅读 25 收藏 0 点赞 0 评论 0
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);
    }
}
EventDataConverter.java 文件源码 项目:logging-log4j2 阅读 27 收藏 0 点赞 0 评论 0
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);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号