logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1434585 - in /logging/log4j/log4j2/trunk: api/src/main/java/org/apache/logging/log4j/ api/src/main/java/org/apache/logging/log4j/simple/ api/src/main/java/org/apache/logging/log4j/status/ api/src/main/java/org/apache/logging/log4j/util/ co...
Date Thu, 17 Jan 2013 08:17:56 GMT
Author: rgoers
Date: Thu Jan 17 08:17:56 2013
New Revision: 1434585

URL: http://svn.apache.org/viewvc?rev=1434585&view=rev
Log:
LOG4J2-150 - Convert all System.getProperty calls to use PropertiesUtil to suppress SecurityExceptions.

Added:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
      - copied, changed from r1434492, logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropsUtil.java
Removed:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropsUtil.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/PropertiesUtil.java
Modified:
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
    logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/OptionConverter.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
    logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
    logging/log4j/log4j2/trunk/src/changes/changes.xml

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/LogManager.java
Thu Jan 17 08:17:56 2013
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.spi.Logg
 import org.apache.logging.log4j.spi.LoggerContextFactory;
 import org.apache.logging.log4j.spi.Provider;
 import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.PropsUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.ProviderUtil;
 
 /**
@@ -61,7 +61,7 @@ public class LogManager {
      */
     static {
         // Shortcut binding to force a specific logging implementation.
-        final PropsUtil managerProps = PropsUtil.getComponentProperties();
+        final PropertiesUtil managerProps = PropertiesUtil.getProperties();
         final String factoryClass = managerProps.getStringProperty(FACTORY_PROPERTY_NAME);
         final ClassLoader cl = ProviderUtil.findClassLoader();
         if (factoryClass != null) {

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/ThreadContext.java
Thu Jan 17 08:17:56 2013
@@ -23,7 +23,7 @@ import org.apache.logging.log4j.spi.Logg
 import org.apache.logging.log4j.spi.Provider;
 import org.apache.logging.log4j.spi.ThreadContextMap;
 import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.PropsUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.ProviderUtil;
 
 import java.io.Serializable;
@@ -62,18 +62,21 @@ public final class ThreadContext  {
 
     private static final String THREAD_CONTEXT_KEY = "log4j2.threadContextMap";
 
-    private static boolean all = Boolean.getBoolean(DISABLE_ALL);
+    private static boolean all;
 
-    private static boolean useMap = !(Boolean.getBoolean(DISABLE_MAP) || all);
+    private static boolean useMap;
 
-    private static boolean useStack = !(Boolean.getBoolean(DISABLE_STACK) || all);
+    private static boolean useStack;
 
     private static ThreadContextMap contextMap;
 
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     static {
-        final PropsUtil managerProps = PropsUtil.getComponentProperties();
+        final PropertiesUtil managerProps = PropertiesUtil.getProperties();
+        all = managerProps.getBooleanProperty(DISABLE_ALL);
+        useMap = !(managerProps.getBooleanProperty(DISABLE_MAP) || all);
+        useStack = !(managerProps.getBooleanProperty(DISABLE_STACK) || all);
         String threadContextMapName = managerProps.getStringProperty(THREAD_CONTEXT_KEY);
         final ClassLoader cl = ProviderUtil.findClassLoader();
         if (threadContextMapName != null) {

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLogger.java
Thu Jan 17 08:17:56 2013
@@ -29,7 +29,7 @@ import org.apache.logging.log4j.ThreadCo
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.spi.AbstractLogger;
-import org.apache.logging.log4j.util.PropsUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
  *  This is the default logger that is used when no suitable logging implementation is available.
@@ -57,7 +57,7 @@ public class SimpleLogger extends Abstra
 
     public SimpleLogger(final String name, final Level defaultLevel, final boolean showLogName,
final boolean showShortLogName,
                         final boolean showDateTime, final boolean showContextMap, final String
dateTimeFormat,
-                        final MessageFactory messageFactory, final PropsUtil props, final
PrintStream stream) {
+                        final MessageFactory messageFactory, final PropertiesUtil props,
final PrintStream stream) {
         super(name, messageFactory);
         final String lvl = props.getStringProperty(SimpleLoggerContext.SYSTEM_PREFIX + name
+ ".level");
         this.level = Level.toLevel(lvl, defaultLevel);

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/simple/SimpleLoggerContext.java
Thu Jan 17 08:17:56 2013
@@ -28,7 +28,7 @@ import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.spi.AbstractLogger;
 import org.apache.logging.log4j.spi.LoggerContext;
-import org.apache.logging.log4j.util.PropsUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
  *
@@ -44,7 +44,7 @@ public class SimpleLoggerContext impleme
     /** Properties loaded from simplelog.properties */
     private final Properties simpleLogProps = new Properties();
 
-    private final PropsUtil props;
+    private final PropertiesUtil props;
 
     /** Include the instance name in the log message? */
     private final boolean showLogName;
@@ -65,7 +65,7 @@ public class SimpleLoggerContext impleme
     private final PrintStream stream;
 
     public SimpleLoggerContext() {
-        props = new PropsUtil("log4j2.simplelog.properties");
+        props = new PropertiesUtil("log4j2.simplelog.properties");
 
         showContextMap = props.getBooleanProperty(SYSTEM_PREFIX + "showContextMap", false);
         showLogName = props.getBooleanProperty(SYSTEM_PREFIX + "showlogname", false);

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusConsoleListener.java
Thu Jan 17 08:17:56 2013
@@ -17,6 +17,7 @@
 package org.apache.logging.log4j.status;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.io.PrintStream;
 
@@ -39,7 +40,7 @@ public class StatusConsoleListener imple
      * default value of FATAL.
      */
     public StatusConsoleListener() {
-        final String str = System.getProperty(STATUS_LEVEL);
+        final String str = PropertiesUtil.getProperties().getStringProperty(STATUS_LEVEL);
         if (str != null) {
             level = Level.toLevel(str, Level.FATAL);
         }

Modified: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/status/StatusLogger.java
Thu Jan 17 08:17:56 2013
@@ -21,7 +21,7 @@ import org.apache.logging.log4j.spi.Abst
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.Marker;
 import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.util.PropsUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -60,7 +60,7 @@ public final class StatusLogger extends 
     private final ReentrantLock msgLock = new ReentrantLock();
 
     private StatusLogger() {
-        final PropsUtil props = new PropsUtil("log4j2.StatusLogger.properties");
+        final PropertiesUtil props = new PropertiesUtil("log4j2.StatusLogger.properties");
         this.logger = new SimpleLogger("StatusLogger", Level.ERROR, false, true, false, false,
"", null, props, System.err);
     }
 
@@ -246,7 +246,7 @@ public final class StatusLogger extends 
     private class BoundedQueue<E> extends ConcurrentLinkedQueue<E> {
 
         private static final long serialVersionUID = -3945953719763255337L;
-        
+
         private final int size;
 
         public BoundedQueue(final int size) {

Copied: logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
(from r1434492, logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropsUtil.java)
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java?p2=logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java&p1=logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropsUtil.java&r1=1434492&r2=1434585&rev=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropsUtil.java
(original)
+++ logging/log4j/log4j2/trunk/api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
Thu Jan 17 08:17:56 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.logging.log4j.util;
 
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.status.StatusLogger;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
@@ -23,21 +26,23 @@ import java.util.Properties;
 /**
  * Utility class to help with accessing System Properties.
  */
-public class PropsUtil {
+public class PropertiesUtil {
 
     private final Properties props;
 
-    private static final PropsUtil LOG4J_PROPERTIES = new PropsUtil("log4j2.component.properties");
+    private static final PropertiesUtil LOG4J_PROPERTIES = new PropertiesUtil("log4j2.component.properties");
+
+    private Logger logger;
 
-    public static PropsUtil getComponentProperties() {
+    public static PropertiesUtil getProperties() {
         return LOG4J_PROPERTIES;
     }
 
-    public PropsUtil(final Properties props) {
+    public PropertiesUtil(final Properties props) {
         this.props = props;
     }
 
-    public PropsUtil(final String propsLocn) {
+    public PropertiesUtil(final String propsLocn) {
         this.props = new Properties();
         final ClassLoader loader = ProviderUtil.findClassLoader();
         final InputStream in = loader.getResourceAsStream(propsLocn);
@@ -71,8 +76,26 @@ public class PropsUtil {
         return (prop == null) ? defaultValue : prop;
     }
 
+    public boolean getBooleanProperty(final String name) {
+        return getBooleanProperty(name, false);
+    }
+
     public boolean getBooleanProperty(final String name, final boolean defaultValue) {
         final String prop = getStringProperty(name);
         return (prop == null) ? defaultValue : "true".equalsIgnoreCase(prop);
     }
+
+    /**
+     * Return the system properties or an empty Properties object if an error occurs.
+     * @return The system properties.
+     */
+    public static Properties getSystemProperties() {
+        try {
+            return new Properties(System.getProperties());
+        } catch (final SecurityException ex) {
+            StatusLogger.getLogger().error("Unable to access system properties.");
+            // Sandboxed - can't read System Properties
+            return new Properties();
+        }
+    }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/appender/ConsoleAppender.java
Thu Jan 17 08:17:56 2013
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.config.plugins.PluginFactory;
 import org.apache.logging.log4j.core.helpers.Loader;
 import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.io.IOException;
 import java.io.OutputStream;
@@ -100,7 +101,9 @@ public final class ConsoleAppender exten
         final PrintStream printStream = target == Target.SYSTEM_OUT ?
             follow ? new PrintStream(new SystemOutStream()) : System.out :
             follow ? new PrintStream(new SystemErrStream()) : System.err;
-        if (!System.getProperty("os.name").startsWith("Windows") || Boolean.getBoolean("log4j.skipJansi"))
{
+        PropertiesUtil propsUtil = PropertiesUtil.getProperties();
+        if (!propsUtil.getStringProperty("os.name").startsWith("Windows") ||
+            propsUtil.getBooleanProperty("log4j.skipJansi")) {
             return printStream;
         } else {
             try {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/BaseConfiguration.java
Thu Jan 17 08:17:56 2013
@@ -39,6 +39,7 @@ import org.apache.logging.log4j.core.loo
 import org.apache.logging.log4j.core.lookup.StrLookup;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Array;
@@ -222,14 +223,16 @@ public class BaseConfiguration extends A
         setName(DefaultConfiguration.DEFAULT_NAME);
         final Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level
%logger{36} - %msg%n",
             null, null, null);
-        final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT",
"Console", "false", "true");
+        final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT",
"Console", "false",
+            "true");
         appender.start();
         addAppender(appender);
         final LoggerConfig root = getRootLogger();
         root.addAppender(appender, null, null);
 
-        final String levelName = System.getProperty(DefaultConfiguration.DEFAULT_LEVEL);
-        final Level level = levelName != null && Level.valueOf(levelName) != null
? Level.valueOf(levelName) : Level.ERROR;
+        final String levelName = PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
+        final Level level = levelName != null && Level.valueOf(levelName) != null
?
+            Level.valueOf(levelName) : Level.ERROR;
         root.setLevel(level);
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
Thu Jan 17 08:17:56 2013
@@ -22,6 +22,8 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.core.helpers.FileUtils;
 import org.apache.logging.log4j.core.helpers.Loader;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -53,7 +55,7 @@ import java.util.TreeSet;
  * factory to be the first one inspected. See
  * {@linkplain XMLConfigurationFactory} for an example.</li>
  * </ol>
- * 
+ *
  * If the ConfigurationFactory that was added returns null on a call to
  * getConfiguration the any other ConfigurationFactories found as plugins will
  * be called in their respective order. DefaultConfiguration is always called
@@ -94,7 +96,7 @@ public abstract class ConfigurationFacto
      * @return the ConfigurationFactory.
      */
     public static ConfigurationFactory getInstance() {
-        final String factoryClass = System.getProperty(CONFIGURATION_FACTORY_PROPERTY);
+        final String factoryClass = PropertiesUtil.getProperties().getStringProperty(CONFIGURATION_FACTORY_PROPERTY);
         if (factoryClass != null) {
             addFactory(factoryClass);
         }
@@ -322,7 +324,7 @@ public abstract class ConfigurationFacto
         public Configuration getConfiguration(final String name, final URI configLocation)
{
 
             if (configLocation == null) {
-                final String config = System.getProperty(CONFIGURATION_FILE_PROPERTY);
+                final String config = PropertiesUtil.getProperties().getStringProperty(CONFIGURATION_FILE_PROPERTY);
                 if (config != null) {
                     final ClassLoader loader = this.getClass().getClassLoader();
                     final ConfigurationSource source = getInputFromString(config, loader);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
Thu Jan 17 08:17:56 2013
@@ -21,6 +21,7 @@ import org.apache.logging.log4j.core.App
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.layout.PatternLayout;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
  * The default configuration writes all output to the Console using the default logging level.
You configure default logging level by setting the
@@ -46,14 +47,16 @@ public class DefaultConfiguration extend
         setName(DEFAULT_NAME);
         final Layout layout = PatternLayout.createLayout("%d{HH:mm:ss.SSS} [%thread] %-5level
%logger{36} - %msg%n",
             null, null, null);
-        final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT",
"Console", "false", "true");
+        final Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT",
"Console", "false",
+            "true");
         appender.start();
         addAppender(appender);
         final LoggerConfig root = getRootLogger();
         root.addAppender(appender, null, null);
 
-        final String levelName = System.getProperty(DEFAULT_LEVEL);
-        final Level level = levelName != null && Level.valueOf(levelName) != null
? Level.valueOf(levelName) : Level.ERROR;
+        final String levelName = PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
+        final Level level = levelName != null && Level.valueOf(levelName) != null
?
+            Level.valueOf(levelName) : Level.ERROR;
         root.setLevel(level);
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Constants.java
Thu Jan 17 08:17:56 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.helpers;
 
+import org.apache.logging.log4j.util.PropertiesUtil;
+
 /**
  * Log4j Constants.
  */
@@ -34,7 +36,7 @@ public final class Constants {
     /**
      * Line separator.
      */
-    public static final String LINE_SEP = PropertiesUtil.getSystemProperty("line.separator",
"\n");
+    public static final String LINE_SEP = PropertiesUtil.getProperties().getStringProperty("line.separator",
"\n");
 
     /**
      * Number of milliseconds in a second.

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/Loader.java
Thu Jan 17 08:17:56 2013
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.he
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.io.InputStream;
 import java.io.InterruptedIOException;
@@ -36,7 +37,7 @@ public final class Loader {
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     static {
-        final String ignoreTCLProp = OptionConverter.getSystemProperty("log4j.ignoreTCL",
null);
+        final String ignoreTCLProp = PropertiesUtil.getProperties().getStringProperty("log4j.ignoreTCL",
null);
         if (ignoreTCLProp != null) {
             ignoreTCL = OptionConverter.toBoolean(ignoreTCLProp, true);
         }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/OptionConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/OptionConverter.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/OptionConverter.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/OptionConverter.java
Thu Jan 17 08:17:56 2013
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.he
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 import java.util.Locale;
 import java.util.Properties;
@@ -84,26 +85,6 @@ public final class OptionConverter {
         return sbuf.toString();
     }
 
-
-    /**
-     * Very similar to <code>System.getProperty</code> except
-     * that the {@link SecurityException} is hidden.
-     *
-     * @param key The key to search for.
-     * @param def The default value to return.
-     * @return the string value of the system property, or the default
-     *         value if there is no property with that key.
-     */
-    public static String getSystemProperty(final String key, final String def) {
-        try {
-            return System.getProperty(key, def);
-        } catch (final Throwable e) { // MS-Java throws com.ms.security.SecurityExceptionEx
-            LOGGER.debug("Was not allowed to read system property \"" + key + "\".");
-            return def;
-        }
-    }
-
-
     public static Object instantiateByKey(final Properties props, final String key, final
Class<?> superClass,
                                    final Object defaultValue) {
 
@@ -327,7 +308,7 @@ public final class OptionConverter {
                     j += DELIM_START_LEN;
                     final String key = val.substring(j, k);
                     // first try in System properties
-                    String replacement = getSystemProperty(key, null);
+                    String replacement = PropertiesUtil.getProperties().getStringProperty(key,
null);
                     // then try props parameter
                     if (replacement == null && props != null) {
                         replacement = props.getProperty(key);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/helpers/UUIDUtil.java
Thu Jan 17 08:17:56 2013
@@ -16,6 +16,8 @@
  */
 package org.apache.logging.log4j.core.helpers;
 
+import org.apache.logging.log4j.util.PropertiesUtil;
+
 import java.lang.reflect.Method;
 import java.net.InetAddress;
 import java.net.NetworkInterface;
@@ -115,7 +117,7 @@ public final class UUIDUtil {
         long rand = uuidSequence;
         final Runtime runtime = Runtime.getRuntime();
         synchronized (runtime) {
-            String assigned = System.getProperty(ASSIGNED_SEQUENCES);
+            String assigned = PropertiesUtil.getProperties().getStringProperty(ASSIGNED_SEQUENCES);
             long[] sequences;
             if (assigned == null) {
                 sequences = new long[0];

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
Thu Jan 17 08:17:56 2013
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.core.sel
 import org.apache.logging.log4j.core.selector.ContextSelector;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.spi.LoggerContextFactory;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 /**
  * Factory to locate a ContextSelector and then load a LoggerContext.
@@ -37,7 +38,7 @@ public class Log4jContextFactory impleme
      * Constructor that initializes the ContextSelector.
      */
     public Log4jContextFactory() {
-        final String sel = System.getProperty(Constants.LOG4J_CONTEXT_SELECTOR);
+        final String sel = PropertiesUtil.getProperties().getStringProperty(Constants.LOG4J_CONTEXT_SELECTOR);
         if (sel != null) {
             try {
                 final Class clazz = Loader.loadClass(sel);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/lookup/SystemPropertiesLookup.java
Thu Jan 17 08:17:56 2013
@@ -31,7 +31,11 @@ public class SystemPropertiesLookup impl
      * @return The value for the key.
      */
     public String lookup(final String key) {
-        return System.getProperty(key);
+        try {
+            return System.getProperty(key);
+        } catch (Exception ex) {
+            return null;
+        }
     }
 
     /**
@@ -41,6 +45,10 @@ public class SystemPropertiesLookup impl
      * @return The value associated with the key.
      */
     public String lookup(final LogEvent event, final String key) {
-        return System.getProperty(key);
+        try {
+            return System.getProperty(key);
+        } catch (Exception ex) {
+            return null;
+        }
     }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SMTPManager.java
Thu Jan 17 08:17:56 2013
@@ -44,7 +44,7 @@ import org.apache.logging.log4j.core.app
 import org.apache.logging.log4j.core.helpers.CyclicBuffer;
 import org.apache.logging.log4j.core.helpers.NameUtil;
 import org.apache.logging.log4j.core.helpers.NetUtils;
-import org.apache.logging.log4j.core.helpers.PropertiesUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
 
 public class SMTPManager extends AbstractManager {
     private static final SMTPManagerFactory factory = new SMTPManagerFactory();
@@ -123,7 +123,7 @@ public class SMTPManager extends Abstrac
 
     /**
      * Send the contents of the cyclic buffer as an e-mail message.
-     * @param appendEvent 
+     * @param appendEvent
      */
     public void sendEvents(final Layout<?> layout, final LogEvent appendEvent) {
         if (message == null) {
@@ -178,7 +178,7 @@ public class SMTPManager extends Abstrac
             final byte[] bytes = layout.toByteArray(priorEvent);
             out.write(bytes);
         }
-        
+
         final byte[] bytes = layout.toByteArray(appendEvent);
         out.write(bytes);
     }

Modified: logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
(original)
+++ logging/log4j/log4j2/trunk/flume-ng/src/main/java/org/apache/logging/log4j/flume/appender/FlumeEmbeddedManager.java
Thu Jan 17 08:17:56 2013
@@ -24,6 +24,7 @@ import org.apache.flume.node.nodemanager
 import org.apache.logging.log4j.core.appender.ManagerFactory;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.helpers.Constants;
 import org.apache.logging.log4j.core.helpers.NameUtil;
 
 import java.util.Locale;
@@ -42,8 +43,6 @@ public class FlumeEmbeddedManager extend
 
     protected static final String SOURCE_NAME = "log4j-source";
 
-    private static final String LINE_SEP = System.getProperty("file.separator");
-
     private final Log4jEventSource source;
 
     private final String shortName;
@@ -201,8 +200,8 @@ public class FlumeEmbeddedManager extend
                 props.put(name + ".channels", "file");
                 props.put(name + ".channels.file.type", "file");
                 if (dataDir != null && dataDir.length() > 0) {
-                    if (!dataDir.endsWith(LINE_SEP)) {
-                        dataDir = dataDir + LINE_SEP;
+                    if (!dataDir.endsWith(Constants.LINE_SEP)) {
+                        dataDir = dataDir + Constants.LINE_SEP;
                     }
 
                     props.put(name + ".channels.file.checkpointDir", dataDir + "checkpoint");

Modified: logging/log4j/log4j2/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/src/changes/changes.xml?rev=1434585&r1=1434584&r2=1434585&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/src/changes/changes.xml (original)
+++ logging/log4j/log4j2/trunk/src/changes/changes.xml Thu Jan 17 08:17:56 2013
@@ -23,6 +23,9 @@
 
   <body>
     <release version="2.0-beta4" date="TBD" description="Bug fixes and enhancements">
+      <action issue="LOG4J2-150" dev="rgoers" type="fix">
+        Convert all System.getProperty calls to use PropertiesUtil to suppress SecurityExceptions.
+      </action>
       <action issue="LOG4J2-147" dev="rgoers" type="fix" due-to="William Burns">
         ThreadContextMapFilter was matching on the key instead of the value of the key.
       </action>



Mime
View raw message