Search in sources :

Example 1 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ContextDataAttributeConverterTest method testConvertToDatabaseColumn02.

@Test
public void testConvertToDatabaseColumn02() {
    final StringMap map = new SortedArrayStringMap();
    map.putValue("someKey", "coolValue");
    map.putValue("anotherKey", "testValue");
    map.putValue("myKey", "yourValue");
    assertEquals("The converted value is not correct.", map.toString(), this.converter.convertToDatabaseColumn(map));
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.Test)

Example 2 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ContextDataJsonAttributeConverterTest method testConvert01.

@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);
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.Test)

Example 3 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ReadOnlyStringMapResolverTest method test_mdc_flatten.

@Test
void test_mdc_flatten() {
    // Create the log event.
    final SimpleMessage message = new SimpleMessage("Hello, World!");
    final StringMap contextData = new SortedArrayStringMap();
    final String mdcPatternMatchedKey = "mdcKey1";
    final String mdcPatternMatchedValue = "mdcValue1";
    contextData.putValue(mdcPatternMatchedKey, mdcPatternMatchedValue);
    final String mdcPatternMismatchedKey = "mdcKey2";
    final String mdcPatternMismatchedValue = "mdcValue2";
    contextData.putValue(mdcPatternMismatchedKey, mdcPatternMismatchedValue);
    final LogEvent logEvent = Log4jLogEvent.newBuilder().setMessage(message).setContextData(contextData).build();
    // Check the serialized event.
    testReadOnlyStringMapFlatten(mdcPatternMatchedKey, mdcPatternMatchedValue, mdcPatternMismatchedKey, logEvent, "mdc");
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.jupiter.api.Test)

Example 4 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class ReadOnlyStringMapResolverTest method test_mdc_pattern.

@Test
void test_mdc_pattern() {
    // Create the log event.
    final SimpleMessage message = new SimpleMessage("Hello, World!");
    final StringMap contextData = new SortedArrayStringMap();
    final String mdcPatternMatchedKey = "mdcKey1";
    final String mdcPatternMatchedValue = "mdcValue1";
    contextData.putValue(mdcPatternMatchedKey, mdcPatternMatchedValue);
    final String mdcPatternMismatchedKey = "mdcKey2";
    final String mdcPatternMismatchedValue = "mdcValue2";
    contextData.putValue(mdcPatternMismatchedKey, mdcPatternMismatchedValue);
    final LogEvent logEvent = Log4jLogEvent.newBuilder().setMessage(message).setContextData(contextData).build();
    // Check the serialized event.
    testReadOnlyStringMapPattern(mdcPatternMatchedKey, mdcPatternMatchedValue, mdcPatternMismatchedKey, logEvent, "mdc");
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) LogEvent(org.apache.logging.log4j.core.LogEvent) Log4jLogEvent(org.apache.logging.log4j.core.impl.Log4jLogEvent) SimpleMessage(org.apache.logging.log4j.message.SimpleMessage) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) Test(org.junit.jupiter.api.Test)

Example 5 with SortedArrayStringMap

use of org.apache.logging.log4j.util.SortedArrayStringMap in project logging-log4j2 by apache.

the class MDCContextMap method getReadOnlyContextData.

@Override
public StringMap getReadOnlyContextData() {
    final Map<String, String> copy = getCopy();
    if (copy.isEmpty()) {
        return EMPTY_CONTEXT_DATA;
    }
    final StringMap result = new SortedArrayStringMap();
    for (final Entry<String, String> entry : copy.entrySet()) {
        result.putValue(entry.getKey(), entry.getValue());
    }
    return result;
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap)

Aggregations

SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)28 StringMap (org.apache.logging.log4j.util.StringMap)19 LogEvent (org.apache.logging.log4j.core.LogEvent)9 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)9 Test (org.junit.Test)9 Test (org.junit.jupiter.api.Test)9 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)8 Message (org.apache.logging.log4j.message.Message)4 ReadOnlyStringMap (org.apache.logging.log4j.util.ReadOnlyStringMap)4 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Random (java.util.Random)2 LogEventAdapter (org.apache.log4j.bridge.LogEventAdapter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 Marker (org.apache.logging.log4j.Marker)2 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)2 ClockFactoryTest (org.apache.logging.log4j.core.time.ClockFactoryTest)2 JsonTemplateLayout (org.apache.logging.log4j.layout.template.json.JsonTemplateLayout)2