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);
}
use of org.apache.logging.log4j.util.PropertiesUtil in project logging-log4j2 by apache.
the class UrlConnectionFactory method createConnection.
public static HttpURLConnection createConnection(final URL url, final long lastModifiedMillis, final SslConfiguration sslConfiguration) throws IOException {
PropertiesUtil props = PropertiesUtil.getProperties();
List<String> allowed = Arrays.asList(Strings.splitList(props.getStringProperty(ALLOWED_PROTOCOLS, HTTPS).toLowerCase(Locale.ROOT)));
if (allowed.size() == 1 && NO_PROTOCOLS.equals(allowed.get(0))) {
throw new ProtocolException("No external protocols have been enabled");
}
String protocol = url.getProtocol();
if (protocol == null) {
throw new ProtocolException("No protocol was specified on " + url.toString());
}
if (!allowed.contains(protocol)) {
throw new ProtocolException("Protocol " + protocol + " has not been enabled as an allowed protocol");
}
final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
final AuthorizationProvider provider = ConfigurationFactory.authorizationProvider(props);
if (provider != null) {
provider.addAuthorization(urlConnection);
}
urlConnection.setAllowUserInteraction(false);
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setRequestMethod("GET");
if (connectTimeoutMillis > 0) {
urlConnection.setConnectTimeout(connectTimeoutMillis);
}
if (readTimeoutMillis > 0) {
urlConnection.setReadTimeout(readTimeoutMillis);
}
final String[] fileParts = url.getFile().split("\\.");
final String type = fileParts[fileParts.length - 1].trim();
final String contentType = isXml(type) ? XML : isJson(type) ? JSON : isProperties(type) ? PROPERTIES : TEXT;
urlConnection.setRequestProperty("Content-Type", contentType);
if (lastModifiedMillis > 0) {
urlConnection.setIfModifiedSince(lastModifiedMillis);
}
if (url.getProtocol().equals(HTTPS) && sslConfiguration != null) {
((HttpsURLConnection) urlConnection).setSSLSocketFactory(sslConfiguration.getSslSocketFactory());
if (!sslConfiguration.isVerifyHostName()) {
((HttpsURLConnection) urlConnection).setHostnameVerifier(LaxHostnameVerifier.INSTANCE);
}
}
return urlConnection;
}
use of org.apache.logging.log4j.util.PropertiesUtil in project Javacord by BtoBastian.
the class LoggerUtil method getLogger.
/**
* Get or create a logger with the given name.
*
* @param name The name of the logger.
* @return The logger with the given name.
*/
public static Logger getLogger(String name) {
AtomicBoolean logWarning = new AtomicBoolean(false);
initialized.updateAndGet(initialized -> {
if (!initialized && !ProviderUtil.hasProviders()) {
noLogger.set(true);
logWarning.set(true);
}
return true;
});
if (noLogger.get()) {
return loggers.computeIfAbsent(name, key -> {
Level level = FallbackLoggerConfiguration.isTraceEnabled() ? Level.TRACE : (FallbackLoggerConfiguration.isDebugEnabled() ? Level.DEBUG : Level.INFO);
Logger logger = new SimpleLogger(name, level, true, false, true, true, "yyyy-MM-dd HH:mm:ss.SSSZ", null, new PropertiesUtil(new Properties()), System.out);
if (logWarning.get()) {
logger.info("No Log4j2 compatible logger was found. Using default Javacord implementation!");
}
return new PrivacyProtectionLogger(logger);
});
} else {
return new PrivacyProtectionLogger(LogManager.getLogger(name));
}
}
Aggregations