Java 类org.apache.logging.log4j.util.StringMap 实例源码

项目:daikon    文件:Log4j2JSONLayoutTest.java   
@Override
protected Object newEvent(LogDetails logDetails) {
    final Message message = new SimpleMessage(logDetails.getLogMessage());
    final StringMap contextData;
    if (!logDetails.getMdc().isEmpty()) {
        contextData = ContextDataFactory.createContextData();
        logDetails.getMdc().entrySet().forEach(it -> contextData.putValue(it.getKey(), it.getValue()));
    } else {
        contextData = null;
    }
    Log4jLogEvent.Builder builder = Log4jLogEvent.newBuilder().setLoggerName(logDetails.getClassName())
            .setTimeMillis(logDetails.getTimeMillis()).setLevel(Level.DEBUG).setContextData(contextData)
            .setIncludeLocation(logDetails.isLocationInfo()).setLoggerFqcn(logDetails.getClassName()).setMessage(message);
    if (logDetails.isLocationInfo()) {
        builder.setSource(new StackTraceElement(logDetails.getClassName(), logDetails.getMethodName(),
                logDetails.getFileName(), logDetails.getLineNumber()));
    }
    if (logDetails.getException() != null) {
        builder.setThrown(logDetails.getException());
    }
    return builder.build();
}
项目:logging-log4j2    文件:Log4j2AppenderComparisonBenchmark.java   
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(MESSAGE);
    final Throwable t = null;
    final StringMap mdc = null;
    final ThreadContext.ContextStack ndc = null;
    final String threadName = "THREAD";
    final StackTraceElement location = null;
    final long timestamp = System.currentTimeMillis();

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:PatternLayoutBenchmark.java   
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:PatternLayoutComparisonBenchmark.java   
private static LogEvent createLog4j2Event() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:AbstractStringLayoutStringEncodingBenchmark.java   
private static LogEvent createLogEvent(final Message message) {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final org.apache.logging.log4j.Level level = org.apache.logging.log4j.Level.DEBUG;
    final Throwable t = null;
    final StringMap mdc = null;
    final ThreadContext.ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
        .setLoggerName("name(ignored)") //
        .setMarker(marker) //
        .setLoggerFqcn(fqcn) //
        .setLevel(level) //
        .setMessage(message) //
        .setThrown(t) //
        .setContextData(mdc) //
        .setContextStack(ndc) //
        .setThreadName(threadName) //
        .setSource(location) //
        .setTimeMillis(timestamp) //
        .build();
}
项目:logging-log4j2    文件:GelfLayoutBenchmark.java   
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final org.apache.logging.log4j.Level level = org.apache.logging.log4j.Level.DEBUG;
    final Message message = new SimpleMessage(MESSAGE);
    final Throwable t = null;
    final StringMap mdc = null;
    final ThreadContext.ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:TextEncoderHelperBenchmark.java   
private static LogEvent createLogEvent() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
private ThreadLocal<StringMap> createThreadLocalMap() {
    if (inheritableMap) {
        return new InheritableThreadLocal<StringMap>() {
            @Override
            protected StringMap childValue(final StringMap parentValue) {
                if (parentValue == null) {
                    return null;
                }
                StringMap stringMap = createStringMap(parentValue);
                stringMap.freeze();
                return stringMap;
            }
        };
    }
    // if not inheritable, return plain ThreadLocal with null as initial value
    return new ThreadLocal<>();
}
项目:logging-log4j2    文件:RingBufferLogEventTest.java   
@Test
public void testGetMessageReturnsNonNullMessage() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(), new DummyNanoClock(1));
    assertNotNull(evt.getMessage());
}
项目:logging-log4j2    文件:ContextDataJsonAttributeConverter.java   
@Override
public ReadOnlyStringMap convertToEntityAttribute(final String s) {
    if (Strings.isEmpty(s)) {
        return null;
    }
    try {
        final StringMap result = ContextDataFactory.createContextData();
        final ObjectNode root = (ObjectNode) OBJECT_MAPPER.readTree(s);
        final Iterator<Map.Entry<String, JsonNode>> entries = root.fields();
        while (entries.hasNext()) {
            final Map.Entry<String, JsonNode> entry = entries.next();

            // Don't know what to do with non-text values.
            // Maybe users who need this need to provide custom converter?
            final Object value = entry.getValue().textValue();
            result.putValue(entry.getKey(), value);
        }
        return result;
    } catch (final IOException e) {
        throw new PersistenceException("Failed to convert JSON string to map.", e);
    }
}
项目:logging-log4j2    文件:ContextDataJsonAttributeConverterTest.java   
@Test
public void testConvert02() {
    final StringMap map = new SortedArrayStringMap();
    map.putValue("someKey", "coolValue");
    map.putValue("anotherKey", "testValue");
    map.putValue("myKey", "yourValue");

    final String converted = this.converter.convertToDatabaseColumn(map);

    assertNotNull("The converted value should not be null.", converted);

    final ReadOnlyStringMap reversed = this.converter.convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", map, reversed);
}
项目:logging-log4j2    文件:ContextDataDeserializer.java   
@Override
    public StringMap deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException,
            JsonProcessingException {

        // Sanity check: verify that we got "Json Object":
//        JsonToken tok = jp.nextToken();
//        if (tok != JsonToken.START_OBJECT) {
//            throw new IOException("Expected data to start with an Object");
//        }
        final StringMap contextData = ContextDataFactory.createContextData();
        // Iterate over object fields:
        while (jp.nextToken() != JsonToken.END_OBJECT) {
            final String fieldName = jp.getCurrentName();

            // move to value
            jp.nextToken();
            contextData.putValue(fieldName, jp.getText());
        }
        return contextData;
    }
项目:logging-log4j2    文件:Log4jLogEvent.java   
private Log4jLogEvent(final String loggerName, final Marker marker, final String loggerFQCN, final Level level,
                      final Message message, final Throwable thrown, final ThrowableProxy thrownProxy,
                      final StringMap contextData, final ThreadContext.ContextStack contextStack, final long threadId,
                      final String threadName, final int threadPriority, final StackTraceElement source,
                      final long nanoTime) {
    this.loggerName = loggerName;
    this.marker = marker;
    this.loggerFqcn = loggerFQCN;
    this.level = level == null ? Level.OFF : level; // LOG4J2-462, LOG4J2-465
    this.message = message;
    this.thrown = thrown;
    this.thrownProxy = thrownProxy;
    this.contextData = contextData == null ? ContextDataFactory.createContextData() : contextData;
    this.contextStack = contextStack == null ? ThreadContext.EMPTY_STACK : contextStack;
    this.threadId = threadId;
    this.threadName = threadName;
    this.threadPriority = threadPriority;
    this.source = source;
    if (message instanceof LoggerNameAwareMessage) {
        ((LoggerNameAwareMessage) message).setLoggerName(loggerName);
    }
    this.nanoTime = nanoTime;
}
项目:logging-log4j2    文件:ThreadContextDataInjector.java   
/**
 * If there are no configuration properties, this injector will return the thread context's internal data
 * structure. Otherwise the configuration properties are combined with the thread context key-value pairs into the
 * specified reusable StringMap.
 *
 * @param props list of configuration properties, may be {@code null}
 * @param ignore a {@code StringMap} instance from the log event
 * @return a {@code StringMap} combining configuration properties with thread context data
 */
@Override
public StringMap injectContextData(final List<Property> props, final StringMap ignore) {
    // If there are no configuration properties we want to just return the ThreadContext's StringMap:
    // it is a copy-on-write data structure so we are sure ThreadContext changes will not affect our copy.
    final StringMap immutableCopy = ThreadContext.getThreadContextMap().getReadOnlyContextData();
    if (props == null || props.isEmpty()) {
        return immutableCopy; // this will replace the LogEvent's context data with the returned instance
    }
    // However, if the list of Properties is non-empty we need to combine the properties and the ThreadContext
    // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined
    // and others not, so the LogEvent's context data may have been replaced with an immutable copy from
    // the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it.
    final StringMap result = ContextDataFactory.createContextData(props.size() + immutableCopy.size());
    copyProperties(props, result);
    result.putAll(immutableCopy);
    return result;
}
项目:logging-log4j2    文件:RingBufferLogEvent.java   
public void setValues(final AsyncLogger anAsyncLogger, final String aLoggerName, final Marker aMarker,
                      final String theFqcn, final Level aLevel, final Message msg, final Throwable aThrowable,
                      final StringMap mutableContextData, final ContextStack aContextStack, final long threadId,
                      final String threadName, final int threadPriority, final StackTraceElement aLocation,
                      final Clock clock, final NanoClock nanoClock) {
    this.threadPriority = threadPriority;
    this.threadId = threadId;
    this.level = aLevel;
    this.threadName = threadName;
    this.loggerName = aLoggerName;
    setMessage(msg);
    initTime(clock);
    this.nanoTime = nanoClock.nanoTime();
    this.thrown = aThrowable;
    this.thrownProxy = null;
    this.marker = aMarker;
    this.fqcn = theFqcn;
    this.location = aLocation;
    this.contextData = mutableContextData;
    this.contextStack = aContextStack;
    this.asyncLogger = anAsyncLogger;
}
项目:logging-log4j2    文件:AsyncLogger.java   
@Override
public void translateTo(final RingBufferLogEvent event, final long sequence, final Object... args) {
    // Implementation note: candidate for optimization: exceeds 35 bytecodes.
    final AsyncLogger asyncLogger = (AsyncLogger) args[0];
    final StackTraceElement location = (StackTraceElement) args[1];
    final String fqcn = (String) args[2];
    final Level level = (Level) args[3];
    final Marker marker = (Marker) args[4];
    final Message message = (Message) args[5];
    final Throwable thrown = (Throwable) args[6];

    // needs shallow copy to be fast (LOG4J2-154)
    final ContextStack contextStack = ThreadContext.getImmutableStack();

    final Thread currentThread = Thread.currentThread();
    final String threadName = THREAD_NAME_CACHING_STRATEGY.getThreadName();
    event.setValues(asyncLogger, asyncLogger.getName(), marker, fqcn, level, message, thrown,
            // config properties are taken care of in the EventHandler thread
            // in the AsyncLogger#actualAsyncLog method
            CONTEXT_DATA_INJECTOR.injectContextData(null, (StringMap) event.getContextData()),
            contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location,
            CLOCK, nanoClock);
}
项目:logging-log4j2    文件:RingBufferLogEventTest.java   
@Test
public void testGetMillisReturnsConstructorMillisForNormalMessage() {
    final RingBufferLogEvent evt = new RingBufferLogEvent();
    final String loggerName = null;
    final Marker marker = null;
    final String fqcn = null;
    final Level level = null;
    final Message data = null;
    final Throwable t = null;
    final ContextStack contextStack = null;
    final String threadName = null;
    final StackTraceElement location = null;
    evt.setValues(null, loggerName, marker, fqcn, level, data, t, (StringMap) evt.getContextData(),
            contextStack, -1, threadName, -1, location, new FixedPreciseClock(123, 456), new DummyNanoClock(1));
    assertEquals(123, evt.getTimeMillis());
    assertEquals(456, evt.getInstant().getNanoOfMillisecond());
}
项目:logging-log4j2    文件:ThreadLocalVsPoolBenchmark.java   
private static LogEvent createLog4j2Event() {
    final Marker marker = null;
    final String fqcn = "com.mycom.myproject.mypackage.MyClass";
    final Level level = Level.DEBUG;
    final String STR = "AB!(%087936DZYXQWEIOP$#^~-=/><nb"; // length=32
    final Message message = new SimpleMessage(STR);
    final Throwable t = null;
    final StringMap mdc = null;
    final ContextStack ndc = null;
    final String threadName = null;
    final StackTraceElement location = null;
    final long timestamp = 12345678;

    return Log4jLogEvent.newBuilder() //
            .setLoggerName("name(ignored)") //
            .setMarker(marker) //
            .setLoggerFqcn(fqcn) //
            .setLevel(level) //
            .setMessage(message) //
            .setThrown(t) //
            .setContextData(mdc) //
            .setContextStack(ndc) //
            .setThreadName(threadName) //
            .setSource(location) //
            .setTimeMillis(timestamp) //
            .build();
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
private ThreadLocal<StringMap> createThreadLocalMap() {
    if (inheritableMap) {
        return new InheritableThreadLocal<StringMap>() {
            @Override
            protected StringMap childValue(final StringMap parentValue) {
                return parentValue != null ? createStringMap(parentValue) : null;
            }
        };
    }
    // if not inheritable, return plain ThreadLocal with null as initial value
    return new ThreadLocal<>();
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
private StringMap getThreadLocalMap() {
    StringMap map = localMap.get();
    if (map == null) {
        map = createStringMap();
        localMap.set(map);
    }
    return map;
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public void putAll(final Map<String, String> values) {
    if (values == null || values.isEmpty()) {
        return;
    }
    final StringMap map = getThreadLocalMap();
    for (final Map.Entry<String, String> entry : values.entrySet()) {
        map.putValue(entry.getKey(), entry.getValue());
    }
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public <V> void putAllValues(final Map<String, V> values) {
    if (values == null || values.isEmpty()) {
        return;
    }
    final StringMap map = getThreadLocalMap();
    for (final Map.Entry<String, V> entry : values.entrySet()) {
        map.putValue(entry.getKey(), entry.getValue());
    }
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public void remove(final String key) {
    final StringMap map = localMap.get();
    if (map != null) {
        map.remove(key);
    }
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public void removeAll(final Iterable<String> keys) {
    final StringMap map = localMap.get();
    if (map != null) {
        for (final String key : keys) {
            map.remove(key);
        }
    }
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public void clear() {
    final StringMap map = localMap.get();
    if (map != null) {
        map.clear();
    }
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
/**
 * {@inheritDoc}
 */
@Override
public StringMap getReadOnlyContextData() {
    StringMap map = localMap.get();
    if (map == null) {
        map = createStringMap();
        localMap.set(map);
    }
    return map;
}
项目:logging-log4j2    文件:GarbageFreeSortedArrayThreadContextMap.java   
@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    final StringMap map = this.localMap.get();
    result = prime * result + ((map == null) ? 0 : map.hashCode());
    return result;
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public void putValue(final String key, final Object value) {
    StringMap map = localMap.get();
    map = map == null ? createStringMap() : createStringMap(map);
    map.putValue(key, value);
    map.freeze();
    localMap.set(map);
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public void putAll(final Map<String, String> values) {
    if (values == null || values.isEmpty()) {
        return;
    }
    StringMap map = localMap.get();
    map = map == null ? createStringMap() : createStringMap(map);
    for (final Map.Entry<String, String> entry : values.entrySet()) {
        map.putValue(entry.getKey(), entry.getValue());
    }
    map.freeze();
    localMap.set(map);
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public <V> void putAllValues(final Map<String, V> values) {
    if (values == null || values.isEmpty()) {
        return;
    }
    StringMap map = localMap.get();
    map = map == null ? createStringMap() : createStringMap(map);
    for (final Map.Entry<String, V> entry : values.entrySet()) {
        map.putValue(entry.getKey(), entry.getValue());
    }
    map.freeze();
    localMap.set(map);
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public void remove(final String key) {
    final StringMap map = localMap.get();
    if (map != null) {
        final StringMap copy = createStringMap(map);
        copy.remove(key);
        copy.freeze();
        localMap.set(copy);
    }
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public void removeAll(final Iterable<String> keys) {
    final StringMap map = localMap.get();
    if (map != null) {
        final StringMap copy = createStringMap(map);
        for (final String key : keys) {
            copy.remove(key);
        }
        copy.freeze();
        localMap.set(copy);
    }
}
项目:logging-log4j2    文件:CopyOnWriteSortedArrayThreadContextMap.java   
@Override
public int hashCode() {
    final int prime = 31;
    int result = 1;
    final StringMap map = this.localMap.get();
    result = prime * result + ((map == null) ? 0 : map.hashCode());
    return result;
}
项目:logging-log4j2    文件:Log4j1MdcPatternConverterTest.java   
@Test
public void testConverter1() {
    final StringMap contextMap = ContextDataFactory.createContextData(1);
    contextMap.putValue("key1", "value1");
    final String expected = "{{key1,value1}}";
    test(contextMap, expected, null);
}
项目:logging-log4j2    文件:Log4j1MdcPatternConverterTest.java   
@Test
public void testConverter2() {
    final StringMap contextMap = ContextDataFactory.createContextData(2);
    contextMap.putValue("key1", "value1");
    contextMap.putValue("key2", "value2");
    final String expected = "{{key1,value1}{key2,value2}}";
    test(contextMap, expected, null);
}
项目:logging-log4j2    文件:Log4j1MdcPatternConverterTest.java   
@Test
public void testConverterWithKey() {
    final StringMap contextMap = ContextDataFactory.createContextData(2);
    contextMap.putValue("key1", "value1");
    contextMap.putValue("key2", "value2");
    final String expected = "value1";
    test(contextMap, expected, new String[] {"key1"});
}
项目:logging-log4j2    文件:Log4j1MdcPatternConverterTest.java   
private void test(final StringMap contextMap, final String expected, final String[] options) {
    final LogEvent event = Log4jLogEvent.newBuilder()
            .setLoggerName("MyLogger")
            .setLevel(Level.DEBUG)
            .setMessage(new SimpleMessage("Hello"))
            .setContextData(contextMap)
            .build();
    final StringBuilder sb = new StringBuilder();
    final Log4j1MdcPatternConverter converter = Log4j1MdcPatternConverter.newInstance(options);
    converter.format(event, sb);
    assertEquals(expected, sb.toString());
}
项目:logging-log4j2    文件:Log4j1XmlLayoutTest.java   
@Test
public void testWithPropertiesAndLocationInfo() {
    final Log4j1XmlLayout layout = Log4j1XmlLayout.createLayout(true, true);

    final StringMap contextMap = ContextDataFactory.createContextData(2);
    contextMap.putValue("key1", "value1");
    contextMap.putValue("key2", "value2");
    final Log4jLogEvent event = Log4jLogEvent.newBuilder()
            .setLoggerName("a.B")
            .setLevel(Level.INFO)
            .setMessage(new SimpleMessage("Hello, World"))
            .setTimeMillis(System.currentTimeMillis() + 17)
            .setIncludeLocation(true)
            .setSource(new StackTraceElement("pack.MyClass", "myMethod", "MyClass.java", 17))
            .setContextData(contextMap)
            .build();

    final String result = layout.toSerializable(event);

    final String expected =
            "<log4j:event logger=\"a.B\" timestamp=\"" + event.getTimeMillis() + "\" level=\"INFO\" thread=\"main\">\r\n" +
            "<log4j:message><![CDATA[Hello, World]]></log4j:message>\r\n" +
            "<log4j:locationInfo class=\"pack.MyClass\" method=\"myMethod\" file=\"MyClass.java\" line=\"17\"/>\r\n" +
            "<log4j:properties>\r\n" +
            "<log4j:data name=\"key1\" value=\"value1\"/>\r\n" +
            "<log4j:data name=\"key2\" value=\"value2\"/>\r\n" +
            "</log4j:properties>\r\n"+
            "</log4j:event>\r\n\r\n";

    assertEquals(expected, result);
}
项目:logging-log4j2    文件:ContextDataJsonAttributeConverterTest.java   
@Test
public void testConvert01() {
    final StringMap map = new SortedArrayStringMap();
    map.putValue("test1", "another1");
    map.putValue("key2", "value2");

    final String converted = this.converter.convertToDatabaseColumn(map);

    assertNotNull("The converted value should not be null.", converted);

    final ReadOnlyStringMap reversed = this.converter.convertToEntityAttribute(converted);

    assertNotNull("The reversed value should not be null.", reversed);
    assertEquals("The reversed value is not correct.", map, reversed);
}
项目:logging-log4j2    文件:ContextDataAttributeConverterTest.java   
@Test
public void testConvertToDatabaseColumn01() {
    final StringMap map = new SortedArrayStringMap();
    map.putValue("test1", "another1");
    map.putValue("key2", "value2");

    assertEquals("The converted value is not correct.", map.toString(),
            this.converter.convertToDatabaseColumn(map));
}