public SimpleLoggerContext() { props = new PropertiesUtil("log4j2.simplelog.properties"); showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false); showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false); showShortName = props.getBooleanProperty(SYSTEM_PREFIX + "showShortLogname", true); showDateTime = props.getBooleanProperty(SYSTEM_PREFIX + "showdatetime", false); final String lvl = props.getStringProperty(SYSTEM_PREFIX + "level"); defaultLevel = Level.toLevel(lvl, Level.ERROR); dateTimeFormat = showDateTime ? props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + "dateTimeFormat", DEFAULT_DATE_TIME_FORMAT) : null; final String fileName = props.getStringProperty(SYSTEM_PREFIX + "logFile", SYSTEM_ERR); PrintStream ps; if (SYSTEM_ERR.equalsIgnoreCase(fileName)) { ps = System.err; } else if (SYSTEM_OUT.equalsIgnoreCase(fileName)) { ps = System.out; } else { try { final FileOutputStream os = new FileOutputStream(fileName); ps = new PrintStream(os); } catch (final FileNotFoundException fnfe) { ps = System.err; } } this.stream = ps; }
private static boolean isIgnoreTccl() { // we need to lazily initialize this, but concurrent access is not an issue if (ignoreTCCL == null) { final String ignoreTccl = PropertiesUtil.getProperties().getStringProperty(IGNORE_TCCL_PROPERTY, null); ignoreTCCL = ignoreTccl != null && !"false".equalsIgnoreCase(ignoreTccl.trim()); } return ignoreTCCL; }
@Test public void testGetMappedProperty_sun_stdout_encoding() { final PropertiesUtil pu = new PropertiesUtil(System.getProperties()); Charset expected = System.console() == null ? Charset.defaultCharset() : StandardCharsets.UTF_8; assertEquals(expected, pu.getCharsetProperty("sun.stdout.encoding")); }
/** * 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); }
/** * 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); }
static void init() { inheritableMap = PropertiesUtil.getProperties().getBooleanProperty(INHERITABLE_MAP); }
private static int size(final String property, final int defaultValue) { return PropertiesUtil.getProperties().getIntegerProperty(property, defaultValue); }
/** * Makes sure we do not blow up with exception below due to a security manager * rejecting environment variable access in * {@link SystemPropertiesPropertySource}. * * <pre> * </pre> */ @Test public void test() { final PropertiesUtil propertiesUtil = new PropertiesUtil(TEST_FIXTURE_PATH); Assert.assertEquals(null, propertiesUtil.getStringProperty("a.1")); } }
/** * Gets the named property as a String. * * @param name the name of the property to look up * @param defaultValue the default value to use if the property is undefined * @return the String value of the property or {@code defaultValue} if undefined. */ public String getStringProperty(final String name, final String defaultValue) { final String prop = getStringProperty(name); return (prop == null) ? defaultValue : prop; }
protected Charset getCharset(final String property, Charset defaultCharset) { return new PropertiesUtil(PropertiesUtil.getSystemProperties()).getCharsetProperty(property, defaultCharset); }
@Before public void setUp() throws Exception { System.clearProperty(AsyncQueueFullPolicyFactory.PROPERTY_NAME_ASYNC_EVENT_ROUTER); System.clearProperty(AsyncQueueFullPolicyFactory.PROPERTY_NAME_DISCARDING_THRESHOLD_LEVEL); PropertiesUtil.getProperties().reload(); }
throw new IllegalStateException("Unsupported default encoding " + enc, ex); final PropertiesUtil propsUtil = PropertiesUtil.getProperties(); if (!propsUtil.isOsWindows() || propsUtil.getBooleanProperty("log4j.skipJansi") || direct) { return outputStream;
@Test public void testIsGemfireObject() { assertTrue("Instances of Function are GemFire objects", InternalDataSerializer.isGemfireObject(new TestFunction())); assertFalse("Instances of PdxSerializaerObject are NOT GemFire objects", InternalDataSerializer.isGemfireObject(new TestPdxSerializerObject())); assertFalse("Instances of anything under org.apache. are GemFire objects", InternalDataSerializer.isGemfireObject(new SimpleLogger("", Level.OFF, false, false, false, false, "", null, new PropertiesUtil(new Properties()), null))); assertTrue("Instances of anything in org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new InternalGemFireException())); assertTrue("Instances of anything under org.apache.geode. are GemFire objects", InternalDataSerializer.isGemfireObject(new ExampleSecurityManager())); }
private static long sleepMillis() { return PropertiesUtil.getProperties().getLongProperty("log4j.waitMillisBeforeStopOldConfig", DEFAULT_SLEEP_MILLIS); }
/** * Gets the named property as a Charset value. If we cannot find the named Charset, see if it is mapped in * file {@code Log4j-charsets.properties} on the class path. * * @param name the name of the property to look up * @param defaultValue the default value to use if the property is undefined * @return the Charset value of the property or {@code defaultValue} if undefined. */ public Charset getCharsetProperty(final String name, final Charset defaultValue) { final String charsetName = getStringProperty(name); if (charsetName == null) { return defaultValue; } if (Charset.isSupported(charsetName)) { return Charset.forName(charsetName); } ResourceBundle bundle = getCharsetsResourceBundle(); if (bundle.containsKey(name)) { String mapped = bundle.getString(name); if (Charset.isSupported(mapped)) { return Charset.forName(mapped); } } LowLevelLogUtil.log("Unable to get Charset '" + charsetName + "' for property '" + name + "', using default " + defaultValue + " and continuing."); return defaultValue; }
private <B extends FilterableComponentBuilder<? extends ComponentBuilder<?>>> B addFiltersToComponent( final B componentBuilder, final Properties properties) { final Map<String, Properties> filters = PropertiesUtil.partitionOnCommonPrefixes( PropertiesUtil.extractSubset(properties, "filter")); for (final Map.Entry<String, Properties> entry : filters.entrySet()) { componentBuilder.add(createFilter(entry.getKey().trim(), entry.getValue())); } return componentBuilder; }
/** * Gets the named property as a Charset value. * * @param name the name of the property to look up * @return the Charset value of the property or {@link Charset#defaultCharset()} if undefined. */ public Charset getCharsetProperty(final String name) { return getCharsetProperty(name, Charset.defaultCharset()); }
/** * Makes sure we do not blow up with exception below due to a security manager * rejecting environment variable access in {@link EnvironmentPropertySource}. * * <pre> * java.lang.NoClassDefFoundError: Could not initialize class org.apache.logging.log4j.util.PropertiesUtil * at org.apache.logging.log4j.status.StatusLogger.<clinit>(StatusLogger.java:78) * at org.apache.logging.log4j.core.AbstractLifeCycle.<clinit>(AbstractLifeCycle.java:38) * at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) * at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) * at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) * at java.lang.reflect.Constructor.newInstance(Constructor.java:423) * at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:172) * at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:161) * at org.apache.logging.log4j.core.config.builder.impl.DefaultConfigurationBuilder.build(DefaultConfigurationBuilder.java:1) * at org.apache.logging.log4j.util.EnvironmentPropertySourceSecurityManagerTest.test(EnvironmentPropertySourceSecurityManagerTest.java:55) * </pre> */ @Test public void test() { PropertiesUtil.getProperties(); } }
/** * Gets the named property as a boolean value. If the property matches the string {@code "true"} (case-insensitive), * then it is returned as the boolean value {@code true}. Any other non-{@code null} text in the property is * considered {@code false}. * * @param name the name of the property to look up * @return the boolean value of the property or {@code false} if undefined. */ public boolean getBooleanProperty(final String name) { return getBooleanProperty(name, false); }
@Test public void testExtractSubset() throws Exception { assertHasAllProperties(PropertiesUtil.extractSubset(properties, "a")); assertHasAllProperties(PropertiesUtil.extractSubset(properties, "b.")); assertHasAllProperties(PropertiesUtil.extractSubset(properties, "c.1")); assertHasAllProperties(PropertiesUtil.extractSubset(properties, "dd")); assertEquals(0, properties.size()); }