use of org.apache.logging.log4j.util.PropertiesUtil 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<>();
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class ThreadContextMapFactory method createThreadContextMap.
public static ThreadContextMap createThreadContextMap() {
final PropertiesUtil managerProps = PropertiesUtil.getProperties();
final String threadContextMapName = managerProps.getStringProperty(THREAD_CONTEXT_KEY);
final ClassLoader cl = ProviderUtil.findClassLoader();
ThreadContextMap result = null;
if (threadContextMapName != null) {
try {
final Class<?> clazz = cl.loadClass(threadContextMapName);
if (ThreadContextMap.class.isAssignableFrom(clazz)) {
result = (ThreadContextMap) clazz.newInstance();
}
} catch (final ClassNotFoundException cnfe) {
LOGGER.error("Unable to locate configured ThreadContextMap {}", threadContextMapName);
} catch (final Exception ex) {
LOGGER.error("Unable to create configured ThreadContextMap {}", threadContextMapName, ex);
}
}
if (result == null && ProviderUtil.hasProviders() && LogManager.getFactory() != null) {
//LOG4J2-1658
final String factoryClassName = LogManager.getFactory().getClass().getName();
for (final Provider provider : ProviderUtil.getProviders()) {
if (factoryClassName.equals(provider.getClassName())) {
final Class<? extends ThreadContextMap> clazz = provider.loadThreadContextMap();
if (clazz != null) {
try {
result = clazz.newInstance();
break;
} catch (final Exception e) {
LOGGER.error("Unable to locate or load configured ThreadContextMap {}", provider.getThreadContextMap(), e);
result = createDefaultThreadContextMap();
}
}
}
}
}
if (result == null) {
result = createDefaultThreadContextMap();
}
return result;
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class ThreadContextMapFactory method initPrivate.
/**
* Initializes static variables based on system properties. Normally called when this class is initialized by the VM
* and when Log4j is reconfigured.
*/
private static void initPrivate() {
final PropertiesUtil properties = PropertiesUtil.getProperties();
ThreadContextMapName = properties.getStringProperty(THREAD_CONTEXT_KEY);
GcFreeThreadContextKey = properties.getBooleanProperty(GC_FREE_THREAD_CONTEXT_KEY);
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class CopyOnWriteSortedArrayThreadContextMap method init.
/**
* Initializes static variables based on system properties. Normally called when this class is initialized by the VM
* and when Log4j is reconfigured.
*/
static void init() {
final PropertiesUtil properties = PropertiesUtil.getProperties();
initialCapacity = properties.getIntegerProperty(PROPERTY_NAME_INITIAL_CAPACITY, DEFAULT_INITIAL_CAPACITY);
inheritableMap = properties.getBooleanProperty(INHERITABLE_MAP);
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class GarbageFreeSortedArrayThreadContextMap method init.
/**
* Initializes static variables based on system properties. Normally called when this class is initialized by the VM
* and when Log4j is reconfigured.
*/
static void init() {
final PropertiesUtil properties = PropertiesUtil.getProperties();
initialCapacity = properties.getIntegerProperty(PROPERTY_NAME_INITIAL_CAPACITY, DEFAULT_INITIAL_CAPACITY);
inheritableMap = properties.getBooleanProperty(INHERITABLE_MAP);
}
Aggregations