logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r1404487 - in /logging/log4j/log4j2/trunk: combined/src/test/resources/ core/src/main/java/org/apache/logging/log4j/core/config/ core/src/main/java/org/apache/logging/log4j/core/config/plugins/ core/src/main/java/org/apache/logging/log4j/co...
Date Thu, 01 Nov 2012 07:47:10 GMT
Author: rgoers
Date: Thu Nov  1 07:47:09 2012
New Revision: 1404487

URL: http://svn.apache.org/viewvc?rev=1404487&view=rev
Log:
Most of the fix for LOG4J2-106

Modified:
    logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml
    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/Configurator.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
    logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
    logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
    logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
    logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java

Modified: logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml (original)
+++ logging/log4j/log4j2/trunk/combined/src/test/resources/log4j-test2.xml Thu Nov  1 07:47:09
2012
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<configuration status="debug" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+<configuration status="debug" name="XMLConfigTest" monitorInterval="5" packages="org.apache.logging.log4j.test">
   <properties>
     <property name="filename">target/test.log</property>
   </properties>

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=1404487&r1=1404486&r2=1404487&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 Nov  1 07:47:09 2012
@@ -92,11 +92,6 @@ public abstract class ConfigurationFacto
     private static ConfigurationFactory configFactory = new Factory();
 
     /**
-     * The configuration File.
-     */
-    protected File configFile = null;
-
-    /**
      * Returns the ConfigurationFactory.
      * @return the ConfigurationFactory.
      */
@@ -175,7 +170,7 @@ public abstract class ConfigurationFacto
         return true;
     }
 
-    public abstract Configuration getConfiguration(InputSource source);
+    public abstract Configuration getConfiguration(ConfigurationSource source);
 
     /**
      * Returns the Configuration.
@@ -188,7 +183,7 @@ public abstract class ConfigurationFacto
             return null;
         }
         if (configLocation != null) {
-            InputSource source = getInputFromURI(configLocation);
+            ConfigurationSource source = getInputFromURI(configLocation);
             if (source != null) {
                 return getConfiguration(source);
             }
@@ -199,15 +194,13 @@ public abstract class ConfigurationFacto
     /**
      * Load the configuration from a URI.
      * @param configLocation A URI representing the location of the configuration.
-     * @return The InputSource for the configuration.
+     * @return The ConfigurationSource for the configuration.
      */
-    protected InputSource getInputFromURI(URI configLocation) {
-        configFile = FileUtils.fileFromURI(configLocation);
+    protected ConfigurationSource getInputFromURI(URI configLocation) {
+        File configFile = FileUtils.fileFromURI(configLocation);
         if (configFile != null && configFile.exists() && configFile.canRead())
{
             try {
-                InputSource source = new InputSource(new FileInputStream(configFile));
-                source.setSystemId(configFile.getAbsolutePath());
-                return source;
+                return new ConfigurationSource(new FileInputStream(configFile), configFile);
             } catch (FileNotFoundException ex) {
                 LOGGER.error("Cannot locate file " + configLocation.getPath(), ex);
             }
@@ -215,15 +208,13 @@ public abstract class ConfigurationFacto
         String scheme = configLocation.getScheme();
         if (scheme == null || scheme.equals("classloader")) {
             ClassLoader loader = this.getClass().getClassLoader();
-            InputSource source = getInputFromResource(configLocation.getPath(), loader);
+            ConfigurationSource source = getInputFromResource(configLocation.getPath(), loader);
             if (source != null) {
                 return source;
             }
         }
         try {
-            InputSource source = new InputSource(configLocation.toURL().openStream());
-            source.setSystemId(configLocation.getPath());
-            return source;
+            return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.getPath());
         } catch (MalformedURLException ex) {
             LOGGER.error("Invalid URL " + configLocation.toString(), ex);
         } catch (IOException ex) {
@@ -240,40 +231,31 @@ public abstract class ConfigurationFacto
      * @param loader The default ClassLoader to use.
      * @return The InputSource to use to read the configuration.
      */
-    protected InputSource getInputFromString(String config, ClassLoader loader) {
-        InputSource source;
+    protected ConfigurationSource getInputFromString(String config, ClassLoader loader) {
         try {
             URL url = new URL(config);
-            source = new InputSource(url.openStream());
-            if (FileUtils.isFile(url)) {
-                configFile = FileUtils.fileFromURI(url.toURI());
-            }
-            source.setSystemId(config);
-            return source;
+            return new ConfigurationSource(url.openStream(), FileUtils.fileFromURI(url.toURI()));
         } catch (Exception ex) {
-            source = getInputFromResource(config, loader);
+            ConfigurationSource source = getInputFromResource(config, loader);
             if (source == null) {
                 try {
                     File file = new File(config);
-                    FileInputStream is = new FileInputStream(file);
-                    configFile = file;
-                    source = new InputSource(is);
-                    source.setSystemId(config);
+                    return new ConfigurationSource(new FileInputStream(file), file);
                 } catch (FileNotFoundException fnfe) {
                     // Ignore the exception
                 }
             }
+            return source;
         }
-        return source;
     }
 
     /**
      * Retrieve the configuration via the ClassLoader.
      * @param resource The resource to load.
      * @param loader The default ClassLoader to use.
-     * @return The InputSource for the configuration.
+     * @return The ConfigurationSource for the configuration.
      */
-    protected InputSource getInputFromResource(String resource, ClassLoader loader) {
+    protected ConfigurationSource getInputFromResource(String resource, ClassLoader loader)
{
         URL url = Loader.getResource(resource, loader);
         if (url == null) {
             return null;
@@ -287,16 +269,15 @@ public abstract class ConfigurationFacto
         if (is == null) {
             return null;
         }
-        InputSource source = new InputSource(is);
+
         if (FileUtils.isFile(url)) {
             try {
-                configFile = FileUtils.fileFromURI(url.toURI());
+                return new ConfigurationSource(is, FileUtils.fileFromURI((url.toURI())));
             } catch (URISyntaxException ex) {
                 // Just ignore the exception.
             }
         }
-        source.setSystemId(resource);
-        return source;
+        return new ConfigurationSource(is, resource);
     }
 
     /**
@@ -346,7 +327,7 @@ public abstract class ConfigurationFacto
                 String config = System.getProperty(CONFIGURATION_FILE_PROPERTY);
                 if (config != null) {
                     ClassLoader loader = this.getClass().getClassLoader();
-                    InputSource source = getInputFromString(config, loader);
+                    ConfigurationSource source = getInputFromString(config, loader);
                     if (source != null) {
                         for (ConfigurationFactory factory : factories) {
                             String[] types = factory.getSupportedTypes();
@@ -409,7 +390,7 @@ public abstract class ConfigurationFacto
                     }
                     configName = named ? prefix + name + suffix : prefix + suffix;
 
-                    InputSource source = getInputFromResource(configName, loader);
+                    ConfigurationSource source = getInputFromResource(configName, loader);
                     if (source != null) {
                         return factory.getConfiguration(source);
                     }
@@ -424,9 +405,9 @@ public abstract class ConfigurationFacto
         }
 
         @Override
-        public Configuration getConfiguration(InputSource source) {
+        public Configuration getConfiguration(ConfigurationSource source) {
             if (source != null) {
-                String config = source.getSystemId() != null ? source.getSystemId() : source.getPublicId();
+                String config = source.getLocation();
                 for (ConfigurationFactory factory : factories) {
                     String[] types = factory.getSupportedTypes();
                     if (types != null) {
@@ -448,4 +429,58 @@ public abstract class ConfigurationFacto
             return null;
         }
     }
+
+    public static class ConfigurationSource {
+
+        private File file;
+
+        private String location;
+
+        private InputStream stream;
+
+        public ConfigurationSource() {
+        }
+
+        public ConfigurationSource(InputStream stream) {
+            this.stream = stream;
+            this .file = null;
+            this.location = null;
+        }
+
+        public ConfigurationSource(InputStream stream, File file) {
+            this.stream = stream;
+            this.file = file;
+            this.location = file.getAbsolutePath();
+        }
+
+        public ConfigurationSource(InputStream stream, String location) {
+            this.stream = stream;
+            this.location = location;
+            this.file = null;
+        }
+
+        public File getFile() {
+            return file;
+        }
+
+        public void setFile(File file) {
+            this.file = file;
+        }
+
+        public String getLocation() {
+            return location;
+        }
+
+        public void setLocation(String location) {
+            this.location = location;
+        }
+
+        public InputStream getInputStream() {
+            return stream;
+        }
+
+        public void setInputStream(InputStream stream) {
+            this.stream = stream;
+        }
+    }
 }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/Configurator.java
Thu Nov  1 07:47:09 2012
@@ -75,7 +75,7 @@ public final class Configurator {
      * @param source The InputSource for the configuration.
      * @return The LoggerContext.
      */
-    public static LoggerContext initialize(ClassLoader loader, InputSource source) {
+    public static LoggerContext initialize(ClassLoader loader, ConfigurationFactory.ConfigurationSource
source) {
 
         try {
             LoggerContext ctx = (LoggerContext) LogManager.getContext(loader, false);

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/FileConfigurationMonitor.java
Thu Nov  1 07:47:09 2012
@@ -50,7 +50,7 @@ public class FileConfigurationMonitor im
      * @param reconfigurable The Configuration that can be reconfigured.
      * @param file The File to monitor.
      * @param listeners The List of ConfigurationListeners to notify upon a change.
-     * @param interval The monitor interval in seconds. The minimum interval is 30 seconds.
+     * @param interval The monitor interval in seconds. The minimum interval is 5 seconds.
      */
     public FileConfigurationMonitor(Reconfigurable reconfigurable, File file, List<ConfigurationListener>
listeners,
                                     int interval) {

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfiguration.java
Thu Nov  1 07:47:09 2012
@@ -27,7 +27,6 @@ import org.apache.logging.log4j.status.S
 import org.codehaus.jackson.JsonNode;
 import org.codehaus.jackson.JsonParser;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.xml.sax.InputSource;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -62,16 +61,15 @@ public class JSONConfiguration extends B
 
     private File configFile;
 
-    public JSONConfiguration(InputSource source, File configFile) {
-        this.configFile = configFile;
+    public JSONConfiguration(ConfigurationFactory.ConfigurationSource configSource) {
+        this.configFile = configSource.getFile();
         byte[] buffer;
 
         try {
-            InputStream configStream = source.getByteStream();
+            InputStream configStream = configSource.getInputStream();
             buffer = toByteArray(configStream);
             configStream.close();
             InputStream is = new ByteArrayInputStream(buffer);
-            source = new InputSource(is);
             ObjectMapper mapper = new ObjectMapper().configure(JsonParser.Feature.ALLOW_COMMENTS,
true);
             root = mapper.readTree(is);
             if (root.size() == 1) {
@@ -143,10 +141,10 @@ public class JSONConfiguration extends B
                 }
             }
             if (getName() == null) {
-                setName(source.getSystemId());
+                setName(configSource.getLocation());
             }
         } catch (Exception ex) {
-            LOGGER.error("Error parsing " + source.getSystemId(), ex);
+            LOGGER.error("Error parsing " + configSource.getLocation(), ex);
             ex.printStackTrace();
         }
     }
@@ -177,9 +175,9 @@ public class JSONConfiguration extends B
     public Configuration reconfigure() {
         if (configFile != null) {
             try {
-                InputSource source = new InputSource(new FileInputStream(configFile));
-                source.setSystemId(configFile.getAbsolutePath());
-                return new JSONConfiguration(source, configFile);
+                ConfigurationFactory.ConfigurationSource source =
+                    new ConfigurationFactory.ConfigurationSource(new FileInputStream(configFile),
configFile);
+                return new JSONConfiguration(source);
             } catch (FileNotFoundException ex) {
                 LOGGER.error("Cannot locate file " + configFile, ex);
             }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/JSONConfigurationFactory.java
Thu Nov  1 07:47:09 2012
@@ -61,11 +61,11 @@ public class JSONConfigurationFactory ex
     }
 
     @Override
-    public Configuration getConfiguration(InputSource source) {
+    public Configuration getConfiguration(ConfigurationSource source) {
         if (!isActive) {
             return null;
         }
-        return new JSONConfiguration(source, configFile);
+        return new JSONConfiguration(source);
     }
 
     @Override

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfiguration.java
Thu Nov  1 07:47:09 2012
@@ -83,15 +83,15 @@ public class XMLConfiguration extends Ba
 
     private final File configFile;
 
-    public XMLConfiguration(InputSource source, File configFile) {
-        this.configFile = configFile;
+    public XMLConfiguration(ConfigurationFactory.ConfigurationSource configSource) {
+        this.configFile = configSource.getFile();
         byte[] buffer = null;
 
         try {
-            InputStream configStream = source.getByteStream();
+            InputStream configStream = configSource.getInputStream();
             buffer = toByteArray(configStream);
             configStream.close();
-            source = new InputSource(new ByteArrayInputStream(buffer));
+            InputSource source = new InputSource(new ByteArrayInputStream(buffer));
             DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document document = builder.parse(source);
             rootElement = document.getDocumentElement();
@@ -165,11 +165,11 @@ public class XMLConfiguration extends Ba
             }
 
         } catch (SAXException domEx) {
-            LOGGER.error("Error parsing " + source.getSystemId(), domEx);
+            LOGGER.error("Error parsing " + configSource.getLocation(), domEx);
         } catch (IOException ioe) {
-            LOGGER.error("Error parsing " + source.getSystemId(), ioe);
+            LOGGER.error("Error parsing " + configSource.getLocation(), ioe);
         } catch (ParserConfigurationException pex) {
-            LOGGER.error("Error parsing " + source.getSystemId(), pex);
+            LOGGER.error("Error parsing " + configSource.getLocation(), pex);
         }
         if (strict && schema != null && buffer != null) {
             InputStream is = null;
@@ -201,7 +201,7 @@ public class XMLConfiguration extends Ba
         }
 
         if (getName() == null) {
-            setName(source.getSystemId());
+            setName(configSource.getLocation());
         }
     }
 
@@ -220,9 +220,9 @@ public class XMLConfiguration extends Ba
     public Configuration reconfigure() {
         if (configFile != null) {
             try {
-                InputSource source = new InputSource(new FileInputStream(configFile));
-                source.setSystemId(configFile.getAbsolutePath());
-                return new XMLConfiguration(source, configFile);
+                ConfigurationFactory.ConfigurationSource source =
+                    new ConfigurationFactory.ConfigurationSource(new FileInputStream(configFile),
configFile);
+                return new XMLConfiguration(source);
             } catch (FileNotFoundException ex) {
                 LOGGER.error("Cannot locate file " + configFile, ex);
             }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/XMLConfigurationFactory.java
Thu Nov  1 07:47:09 2012
@@ -37,8 +37,8 @@ public class XMLConfigurationFactory ext
      * @return The Configuration.
      */
     @Override
-    public Configuration getConfiguration(InputSource source) {
-        return new XMLConfiguration(source, configFile);
+    public Configuration getConfiguration(ConfigurationSource source) {
+        return new XMLConfiguration(source);
     }
 
     /**

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/config/plugins/ResolverUtil.java
Thu Nov  1 07:47:09 2012
@@ -276,8 +276,8 @@ public class ResolverUtil<T> {
     }
 
     private void loadImplementationsInBundle(Test test, String packageName) {
-        Collection<String> list = FrameworkUtil.getBundle(ResolverUtil.class).adapt(BundleWiring.class)
-            .listResources(packageName, "*.class", BundleWiring.LISTRESOURCES_RECURSE);
+        BundleWiring wiring = (BundleWiring)FrameworkUtil.getBundle(ResolverUtil.class).adapt(BundleWiring.class);
+        Collection<String> list = wiring.listResources(packageName, "*.class", BundleWiring.LISTRESOURCES_RECURSE);
         for (String name : list) {
             addIfMatching(test, name);
         }

Modified: logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/main/java/org/apache/logging/log4j/core/net/SocketServer.java
Thu Nov  1 07:47:09 2012
@@ -217,20 +217,18 @@ public class SocketServer extends Abstra
         public Configuration getConfiguration(String name, URI configLocation) {
             if (path != null && path.length() > 0) {
                 File file = null;
-                InputSource source = null;
+                ConfigurationSource source = null;
                 try {
                     file = new File(path);
                     FileInputStream is = new FileInputStream(file);
-                    source = new InputSource(is);
-                    source.setSystemId(path);
+                    source = new ConfigurationSource(is, file);
                 } catch (FileNotFoundException ex) {
                     // Ignore this error
                 }
                 if (source == null) {
                     try {
                         URL url = new URL(path);
-                        source = new InputSource(url.openStream());
-                        source.setSystemId(path);
+                        source = new ConfigurationSource(url.openStream(), path);
                     } catch (MalformedURLException mue) {
                         // Ignore this error
                     } catch (IOException ioe) {
@@ -240,7 +238,7 @@ public class SocketServer extends Abstra
 
                 try {
                     if (source != null) {
-                        return new XMLConfiguration(source, file);
+                        return new XMLConfiguration(source);
                     }
                 } catch (Exception ex) {
                     // Ignore this error.

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
Thu Nov  1 07:47:09 2012
@@ -41,7 +41,7 @@ public class BasicConfigurationFactory e
     }
 
     @Override
-    public Configuration getConfiguration(InputSource source) {
+    public Configuration getConfiguration(ConfigurationSource source) {
         return null;
     }
 

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/LoggerTest.java
Thu Nov  1 07:47:09 2012
@@ -25,15 +25,18 @@ import org.apache.logging.log4j.core.con
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.message.StructuredDataMessage;
 import org.junit.AfterClass;
+import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import java.io.File;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
 
 /**
  *
@@ -49,6 +52,17 @@ public class LoggerTest {
     public static void setupClass() {
         System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
         ctx = (LoggerContext) LogManager.getContext(false);
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+        ctx.reconfigure();
+        StatusLogger.getLogger().reset();
+    }
+
+    @Before
+    public void before() {
         config = ctx.getConfiguration();
         for (Map.Entry<String, Appender> entry : config.getAppenders().entrySet())
{
             if (entry.getKey().equals("List")) {
@@ -56,14 +70,10 @@ public class LoggerTest {
                 break;
             }
         }
+        assertNotNull("No Appender", app);
+        app.clear();
     }
 
-    @AfterClass
-    public static void cleanupClass() {
-        System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
-        ctx.reconfigure();
-        StatusLogger.getLogger().reset();
-    }
 
     org.apache.logging.log4j.Logger logger = LogManager.getLogger("LoggerTest");
 
@@ -156,5 +166,20 @@ public class LoggerTest {
         assertTrue("Incorrect number of events. Expected 1, actual " + events.size(), events.size()
== 1);
         app.clear();
     }
+
+    @Test
+    public void testReconfiguration() throws Exception {
+        File file = new File("target/test-classes/" + CONFIG);
+        long orig = file.lastModified();
+        long newTime = orig + 10000;
+        file.setLastModified(newTime);
+        Thread.sleep(6000);
+        for (int i = 0; i < 17; ++i) {
+            logger.debug("Reconfigure");
+        }
+        Configuration cfg = ctx.getConfiguration();
+        assertNotNull("No configuration", cfg);
+        assertTrue("Reconfiguration failed", cfg != config);
+    }
 }
 

Modified: logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
(original)
+++ logging/log4j/log4j2/trunk/core/src/test/java/org/apache/logging/log4j/core/config/TestConfigurator.java
Thu Nov  1 07:47:09 2012
@@ -62,8 +62,8 @@ public class TestConfigurator {
     @Test
     public void testFromStream() throws Exception {
         InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
-        InputSource source = new InputSource(is);
-        source.setSystemId("target/test-classes/log4j2-config.xml");
+        ConfigurationFactory.ConfigurationSource source =
+            new ConfigurationFactory.ConfigurationSource(is, "target/test-classes/log4j2-config.xml");
         LoggerContext ctx = Configurator.initialize(null, source);
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
         Configuration config = ctx.getConfiguration();
@@ -82,7 +82,8 @@ public class TestConfigurator {
     @Test
     public void testFromStreamNoId() throws Exception {
         InputStream is = new FileInputStream("target/test-classes/log4j2-config.xml");
-        InputSource source = new InputSource(is);
+        ConfigurationFactory.ConfigurationSource source =
+            new ConfigurationFactory.ConfigurationSource(is);
         LoggerContext ctx = Configurator.initialize(null, source);
         Logger logger = LogManager.getLogger("org.apache.test.TestConfigurator");
         Configuration config = ctx.getConfiguration();

Modified: logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml (original)
+++ logging/log4j/log4j2/trunk/core/src/test/resources/log4j-test2.xml Thu Nov  1 07:47:09
2012
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<configuration status="debug" name="XMLConfigTest" packages="org.apache.logging.log4j.test">
+<configuration status="debug" name="XMLConfigTest" monitorInterval="5" packages="org.apache.logging.log4j.test">
   <properties>
     <property name="filename">target/test.log</property>
   </properties>

Modified: logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java?rev=1404487&r1=1404486&r2=1404487&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
(original)
+++ logging/log4j/log4j2/trunk/log4j12-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
Thu Nov  1 07:47:09 2012
@@ -36,7 +36,7 @@ public class BasicConfigurationFactory e
     }
 
     @Override
-    public Configuration getConfiguration(InputSource source) {
+    public Configuration getConfiguration(ConfigurationSource source) {
         return new BasicConfiguration();
     }
 



Mime
View raw message