Search in sources :

Example 16 with StringMap

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

the class ContextDataJsonAttributeConverterTest method testConvert02.

@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);
}
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 17 with StringMap

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

the class ContextDataAttributeConverterTest method testConvertToDatabaseColumn01.

@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));
}
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 18 with StringMap

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

the class GarbageFreeSortedArrayThreadContextMap method createThreadLocalMap.

// LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured.
// (This method is package protected for JUnit tests.)
private ThreadLocal<StringMap> createThreadLocalMap() {
    final PropertiesUtil managerProps = PropertiesUtil.getProperties();
    final boolean inheritable = managerProps.getBooleanProperty(INHERITABLE_MAP);
    if (inheritable) {
        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<>();
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap) PropertiesUtil(org.apache.logging.log4j.util.PropertiesUtil)

Example 19 with StringMap

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

the class GarbageFreeSortedArrayThreadContextMap method getThreadLocalMap.

private StringMap getThreadLocalMap() {
    StringMap map = localMap.get();
    if (map == null) {
        map = createStringMap();
        localMap.set(map);
    }
    return map;
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap)

Example 20 with StringMap

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

the class GarbageFreeSortedArrayThreadContextMap method getReadOnlyContextData.

/**
     * {@inheritDoc}
     */
@Override
public StringMap getReadOnlyContextData() {
    StringMap map = localMap.get();
    if (map == null) {
        map = createStringMap();
        localMap.set(map);
    }
    return map;
}
Also used : SortedArrayStringMap(org.apache.logging.log4j.util.SortedArrayStringMap) StringMap(org.apache.logging.log4j.util.StringMap) ReadOnlyStringMap(org.apache.logging.log4j.util.ReadOnlyStringMap)

Aggregations

StringMap (org.apache.logging.log4j.util.StringMap)26 SortedArrayStringMap (org.apache.logging.log4j.util.SortedArrayStringMap)19 ReadOnlyStringMap (org.apache.logging.log4j.util.ReadOnlyStringMap)14 Test (org.junit.Test)8 Marker (org.apache.logging.log4j.Marker)5 ContextStack (org.apache.logging.log4j.ThreadContext.ContextStack)5 Message (org.apache.logging.log4j.message.Message)5 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)4 IOException (java.io.IOException)3 Map (java.util.Map)3 Level (org.apache.logging.log4j.Level)3 LogEvent (org.apache.logging.log4j.core.LogEvent)3 ReusableMessage (org.apache.logging.log4j.message.ReusableMessage)3 HashMap (java.util.HashMap)2 ClockFactoryTest (org.apache.logging.log4j.core.util.ClockFactoryTest)2 ObjectMessage (org.apache.logging.log4j.message.ObjectMessage)2 ReusableObjectMessage (org.apache.logging.log4j.message.ReusableObjectMessage)2 MutableThreadContextStack (org.apache.logging.log4j.spi.MutableThreadContextStack)2 PropertiesUtil (org.apache.logging.log4j.util.PropertiesUtil)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1