Search in sources :

Example 16 with PropertiesUtil

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

Example 17 with PropertiesUtil

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

Example 18 with PropertiesUtil

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

Example 19 with PropertiesUtil

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;
}
Also used : ProtocolException(java.net.ProtocolException) HttpURLConnection(java.net.HttpURLConnection) AuthorizationProvider(org.apache.logging.log4j.core.util.AuthorizationProvider) BasicAuthorizationProvider(org.apache.logging.log4j.core.util.BasicAuthorizationProvider) PropertiesUtil(org.apache.logging.log4j.util.PropertiesUtil) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 20 with PropertiesUtil

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));
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PropertiesUtil(org.apache.logging.log4j.util.PropertiesUtil) Level(org.apache.logging.log4j.Level) Logger(org.apache.logging.log4j.Logger) SimpleLogger(org.apache.logging.log4j.simple.SimpleLogger) Properties(java.util.Properties) SimpleLogger(org.apache.logging.log4j.simple.SimpleLogger)

Aggregations

PropertiesUtil (org.apache.logging.log4j.util.PropertiesUtil)29 Properties (java.util.Properties)7 ArrayList (java.util.ArrayList)6 Level (org.apache.logging.log4j.Level)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Logger (org.apache.logging.log4j.Logger)3 CloseShieldOutputStream (org.apache.logging.log4j.core.util.CloseShieldOutputStream)3 SimpleLogger (org.apache.logging.log4j.simple.SimpleLogger)3 FileNotFoundException (java.io.FileNotFoundException)2 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 PrintStream (java.io.PrintStream)2 HttpURLConnection (java.net.HttpURLConnection)2 ProtocolException (java.net.ProtocolException)2 URISyntaxException (java.net.URISyntaxException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)2 DefaultThreadContextStack (org.apache.logging.log4j.spi.DefaultThreadContextStack)2 NoOpThreadContextMap (org.apache.logging.log4j.spi.NoOpThreadContextMap)2