Search in sources :

Example 1 with StringMap

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

the class AsyncLogger method translateTo.

/*
     * (non-Javadoc)
     *
     * @see com.lmax.disruptor.EventTranslatorVararg#translateTo(java.lang.Object, long, java.lang.Object[])
     */
@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, // in the AsyncLogger#actualAsyncLog method
    CONTEXT_DATA_INJECTOR.injectContextData(null, (StringMap) event.getContextData()), contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location, CLOCK.currentTimeMillis(), nanoClock.nanoTime());
}
Also used : StringMap(org.apache.logging.log4j.util.StringMap) ReusableMessage(org.apache.logging.log4j.message.ReusableMessage) Message(org.apache.logging.log4j.message.Message) Level(org.apache.logging.log4j.Level) Marker(org.apache.logging.log4j.Marker) ContextStack(org.apache.logging.log4j.ThreadContext.ContextStack)

Example 2 with StringMap

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

the class CopyOnWriteSortedArrayThreadContextMap method putValue.

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

Example 3 with StringMap

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

the class CopyOnWriteSortedArrayThreadContextMap method removeAll.

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

Example 4 with StringMap

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

the class CopyOnWriteSortedArrayThreadContextMap method remove.

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

Example 5 with StringMap

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

the class CopyOnWriteSortedArrayThreadContextMap method hashCode.

@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;
}
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