Search in sources :

Example 21 with PropertiesUtil

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

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 22 with PropertiesUtil

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

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 23 with PropertiesUtil

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

the class ThreadContext method init.

/**
 * <em>Consider private, used for testing.</em>
 */
static void init() {
    ThreadContextMapFactory.init();
    contextMap = null;
    final PropertiesUtil managerProps = PropertiesUtil.getProperties();
    boolean disableAll = managerProps.getBooleanProperty(DISABLE_ALL);
    useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || disableAll);
    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;
    }
}
Also used : DefaultThreadContextStack(org.apache.logging.log4j.spi.DefaultThreadContextStack) PropertiesUtil(org.apache.logging.log4j.util.PropertiesUtil) NoOpThreadContextMap(org.apache.logging.log4j.spi.NoOpThreadContextMap) ReadOnlyThreadContextMap(org.apache.logging.log4j.spi.ReadOnlyThreadContextMap)

Example 24 with PropertiesUtil

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

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

Example 25 with PropertiesUtil

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

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

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