use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class ThreadContext method init.
/**
* <em>Consider private, used for testing.</em>
*/
static void init() {
ThreadContextMapFactory.init();
contextMap = null;
final PropertiesUtil managerProps = PropertiesUtil.getProperties();
final boolean disableAll = managerProps.getBooleanProperty(DISABLE_ALL);
useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll);
final boolean useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || disableAll);
contextStack = new DefaultThreadContextStack(useStack);
if (!useMap) {
contextMap = new NoOpThreadContextMap();
} else {
contextMap = ThreadContextMapFactory.createThreadContextMap();
}
if (contextMap instanceof ReadOnlyThreadContextMap) {
readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap;
} else {
readOnlyContextMap = null;
}
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class ConfigurationFactory method getInstance.
/**
* Returns the ConfigurationFactory.
* @return the ConfigurationFactory.
*/
public static ConfigurationFactory getInstance() {
// noinspection DoubleCheckedLocking
if (factories == null) {
LOCK.lock();
try {
if (factories == null) {
final List<ConfigurationFactory> list = new ArrayList<>();
final PropertiesUtil props = PropertiesUtil.getProperties();
final String factoryClass = props.getStringProperty(CONFIGURATION_FACTORY_PROPERTY);
if (factoryClass != null) {
addFactory(list, factoryClass);
}
final PluginManager manager = new PluginManager(CATEGORY);
manager.collectPlugins();
final Map<String, PluginType<?>> plugins = manager.getPlugins();
final List<Class<? extends ConfigurationFactory>> ordered = new ArrayList<>(plugins.size());
for (final PluginType<?> type : plugins.values()) {
try {
ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class));
} catch (final Exception ex) {
LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex);
}
}
Collections.sort(ordered, OrderComparator.getInstance());
for (final Class<? extends ConfigurationFactory> clazz : ordered) {
addFactory(list, clazz);
}
// see above comments about double-checked locking
// noinspection NonThreadSafeLazyInitialization
factories = Collections.unmodifiableList(list);
authorizationProvider = authorizationProvider(props);
}
} finally {
LOCK.unlock();
}
}
LOGGER.debug("Using configurationFactory {}", configFactory);
return configFactory;
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class AsyncQueueFullPolicyFactory method createDiscardingAsyncQueueFullPolicy.
private static AsyncQueueFullPolicy createDiscardingAsyncQueueFullPolicy() {
final PropertiesUtil util = PropertiesUtil.getProperties();
final String level = util.getStringProperty(PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL, Level.INFO.name());
final Level thresholdLevel = Level.toLevel(level, Level.INFO);
LOGGER.debug("Creating custom DiscardingAsyncQueueFullPolicy(discardThreshold:{})", thresholdLevel);
return new DiscardingAsyncQueueFullPolicy(thresholdLevel);
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class ConsoleAppender method getOutputStream.
private static OutputStream getOutputStream(final boolean follow, final boolean direct, final Target target) {
final String enc = Charset.defaultCharset().name();
OutputStream outputStream;
try {
// @formatter:off
outputStream = target == Target.SYSTEM_OUT ? direct ? new FileOutputStream(FileDescriptor.out) : (follow ? new PrintStream(new SystemOutStream(), true, enc) : System.out) : direct ? new FileOutputStream(FileDescriptor.err) : (follow ? new PrintStream(new SystemErrStream(), true, enc) : System.err);
// @formatter:on
outputStream = new CloseShieldOutputStream(outputStream);
} catch (final UnsupportedEncodingException ex) {
// should never happen
throw new IllegalStateException("Unsupported default encoding " + enc, ex);
}
final PropertiesUtil propsUtil = PropertiesUtil.getProperties();
if (!propsUtil.isOsWindows() || propsUtil.getBooleanProperty("log4j.skipJansi", true) || direct) {
return outputStream;
}
try {
// We type the parameter as a wildcard to avoid a hard reference to Jansi.
final Class<?> clazz = Loader.loadClass(JANSI_CLASS);
final Constructor<?> constructor = clazz.getConstructor(OutputStream.class);
return new CloseShieldOutputStream((OutputStream) constructor.newInstance(outputStream));
} catch (final ClassNotFoundException cnfe) {
LOGGER.debug("Jansi is not installed, cannot find {}", JANSI_CLASS);
} catch (final NoSuchMethodException nsme) {
LOGGER.warn("{} is missing the proper constructor", JANSI_CLASS);
} catch (final Exception ex) {
LOGGER.warn("Unable to instantiate {} due to {}", JANSI_CLASS, clean(Throwables.getRootCause(ex).toString()).trim());
}
return outputStream;
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class Log4j2CloudConfigLoggingSystem method getStandardConfigLocations.
@Override
protected String[] getStandardConfigLocations() {
String[] locations = super.getStandardConfigLocations();
PropertiesUtil props = new PropertiesUtil(new Properties());
String location = props.getStringProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
if (location != null) {
List<String> list = new ArrayList<>(Arrays.asList(super.getStandardConfigLocations()));
list.add(location);
locations = list.toArray(new String[0]);
}
return locations;
}
Aggregations