You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by gg...@apache.org on 2016/08/25 22:27:34 UTC

[01/18] logging-log4j2 git commit: First commit for branch for [LOG4J2-1547] The Core AbstractConfiguration should track its LoggerContext.

Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1539 d18e9c951 -> a4ef9a1de


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
index f3429bb..5d7b1f5 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfigurationFactory.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.config.yaml;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -58,11 +59,11 @@ public class YamlConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
         if (!isActive) {
             return null;
         }
-        return new YamlConfiguration(source);
+        return new YamlConfiguration(loggerContext, source);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
index 12b1204..f7b4a83 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/Log4jContextFactory.java
@@ -173,7 +173,7 @@ public class Log4jContextFactory implements LoggerContextFactory, ShutdownCallba
         if (ctx.getState() == LifeCycle.State.INITIALIZED) {
             if (source != null) {
                 ContextAnchor.THREAD_CONTEXT.set(ctx);
-                final Configuration config = ConfigurationFactory.getInstance().getConfiguration(source);
+                final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, source);
                 LOGGER.debug("Starting LoggerContext[name={}] from configuration {}", ctx.getName(), source);
                 ctx.start(config);
                 ContextAnchor.THREAD_CONTEXT.remove();
@@ -234,7 +234,7 @@ public class Log4jContextFactory implements LoggerContextFactory, ShutdownCallba
         if (ctx.getState() == LifeCycle.State.INITIALIZED) {
             if (configLocation != null || name != null) {
                 ContextAnchor.THREAD_CONTEXT.set(ctx);
-                final Configuration config = ConfigurationFactory.getInstance().getConfiguration(name, configLocation);
+                final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, name, configLocation);
                 LOGGER.debug("Starting LoggerContext[name={}] from configuration at {}", ctx.getName(), configLocation);
                 ctx.start(config);
                 ContextAnchor.THREAD_CONTEXT.remove();
@@ -261,7 +261,7 @@ public class Log4jContextFactory implements LoggerContextFactory, ShutdownCallba
                 final List<AbstractConfiguration> configurations = new ArrayList<>(configLocations.size());
                 for (final URI configLocation : configLocations) {
                     final Configuration currentReadConfiguration = ConfigurationFactory.getInstance()
-                            .getConfiguration(name, configLocation);
+                            .getConfiguration(ctx, name, configLocation);
                     if (currentReadConfiguration instanceof AbstractConfiguration) {
                         configurations.add((AbstractConfiguration) currentReadConfiguration);
                     } else {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
index c9ddb90..a2a9288 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/LoggerContextAdmin.java
@@ -132,7 +132,7 @@ public class LoggerContextAdmin extends NotificationBroadcasterSupport implement
             LOGGER.debug("Opening config URL {}", configURL);
             configSource = new ConfigurationSource(configURL.openStream(), configURL);
         }
-        final Configuration config = ConfigurationFactory.getInstance().getConfiguration(configSource);
+        final Configuration config = ConfigurationFactory.getInstance().getConfiguration(loggerContext, configSource);
         loggerContext.start(config);
         LOGGER.debug("Completed remote request to reconfigure.");
     }
@@ -197,7 +197,7 @@ public class LoggerContextAdmin extends NotificationBroadcasterSupport implement
         try {
             final InputStream in = new ByteArrayInputStream(configText.getBytes(charsetName));
             final ConfigurationSource source = new ConfigurationSource(in);
-            final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(source);
+            final Configuration updated = ConfigurationFactory.getInstance().getConfiguration(loggerContext, source);
             loggerContext.start(updated);
             LOGGER.debug("Completed remote request to reconfigure from config text.");
         } catch (final Exception ex) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
index af2ca0f..7350e6d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/net/server/AbstractSocketServer.java
@@ -29,6 +29,7 @@ import java.util.Objects;
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.LogEventListener;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
@@ -57,7 +58,7 @@ public abstract class AbstractSocketServer<T extends InputStream> extends LogEve
         }
 
         @Override
-        public Configuration getConfiguration(final String name, final URI configLocation) {
+        public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) {
             if (Strings.isNotEmpty(path)) {
                 File file = null;
                 ConfigurationSource source = null;
@@ -81,14 +82,14 @@ public abstract class AbstractSocketServer<T extends InputStream> extends LogEve
 
                 try {
                     if (source != null) {
-                        return new XmlConfiguration(source);
+                        return new XmlConfiguration(loggerContext, source);
                     }
                 } catch (final Exception ex) {
                     // Ignore this error.
                 }
                 System.err.println("Unable to process configuration at " + path + ", using default.");
             }
-            return super.getConfiguration(name, configLocation);
+            return super.getConfiguration(loggerContext, name, configLocation);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
index 844192f..6c6f56a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/BasicConfigurationFactory.java
@@ -31,7 +31,7 @@ import org.apache.logging.log4j.core.config.LoggerConfig;
 public class BasicConfigurationFactory extends ConfigurationFactory {
 
     @Override
-    public Configuration getConfiguration(final String name, final URI configLocation) {
+    public Configuration getConfiguration(LoggerContext loggerContext, final String name, final URI configLocation) {
         return new BasicConfiguration();
     }
 
@@ -41,7 +41,7 @@ public class BasicConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
         return null;
     }
 
@@ -50,7 +50,7 @@ public class BasicConfigurationFactory extends ConfigurationFactory {
         private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
 
         public BasicConfiguration() {
-            super(ConfigurationSource.NULL_SOURCE);
+            super(null, ConfigurationSource.NULL_SOURCE);
 
             final LoggerConfig root = getRootLogger();
             final String name = System.getProperty(DEFAULT_LEVEL);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationTest.java
index 4cfe7c3..0c7c569 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/ConfigurationTest.java
@@ -101,6 +101,12 @@ public class ConfigurationTest {
     }
 
     @Test
+    public void testConfigurationLoggerContext() throws Exception {
+        final Configuration configuration = this.ctx.getConfiguration();
+        assertThat(configuration.getLoggerContext(), is(notNullValue()));
+    }
+
+    @Test
     public void testGetLoggerConfigEmpty() throws Exception {
         final Configuration config = this.ctx.getConfiguration();
         assertEquals(config.getRootLogger(), config.getLoggerConfig(Strings.EMPTY));

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java
index d68b40f..126b0f9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/builder/CustomConfigurationFactory.java
@@ -16,8 +16,11 @@
  */
 package org.apache.logging.log4j.core.config.builder;
 
+import java.net.URI;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -26,8 +29,6 @@ import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
 import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
 
-import java.net.URI;
-
 /**
  * Normally this would be a plugin. However, we don't want it used for everything so it will be defined
  * via a system property.
@@ -57,12 +58,12 @@ public class CustomConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
-        return getConfiguration(source.toString(), null);
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
+        return getConfiguration(null, source.toString(), null);
     }
 
     @Override
-    public Configuration getConfiguration(final String name, final URI configLocation) {
+    public Configuration getConfiguration(LoggerContext loggerContext, final String name, final URI configLocation) {
         final ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder();
         return addTestFixtures(name, builder);
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfiguration.java b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfiguration.java
index bd34b52..11815cb 100644
--- a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfiguration.java
+++ b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfiguration.java
@@ -16,9 +16,12 @@
  */
 package org.apache.logging.log4j.configuration;
 
+import java.io.Serializable;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Layout;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.config.AbstractConfiguration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -26,8 +29,6 @@ import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 import org.apache.logging.log4j.util.PropertiesUtil;
 
-import java.io.Serializable;
-
 /**
  * This Configuration is the same as the DefaultConfiguration but shows how a custom configuration can be built
  * programmatically
@@ -50,15 +51,15 @@ public class CustomConfiguration extends AbstractConfiguration {
      */
     public static final String DEFAULT_PATTERN = "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n";
 
-    public CustomConfiguration() {
-        this(ConfigurationSource.NULL_SOURCE);
+    public CustomConfiguration(LoggerContext loggerContext) {
+        this(loggerContext, ConfigurationSource.NULL_SOURCE);
     }
 
     /**
      * Constructor to create the default configuration.
      */
-    public CustomConfiguration(final ConfigurationSource source) {
-        super(source);
+    public CustomConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
+        super(loggerContext, source);
 
         setName(CONFIG_NAME);
         final Layout<? extends Serializable> layout = PatternLayout.newBuilder()

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java
index 7ef0d92..642abe4 100644
--- a/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java
+++ b/log4j-samples/configuration/src/main/java/org/apache/logging/log4j/configuration/CustomConfigurationFactory.java
@@ -16,12 +16,14 @@
  */
 package org.apache.logging.log4j.configuration;
 
+import java.net.URI;
+
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.Order;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
-import java.net.URI;
 
 /**
  * Factory to construct a  CustomConfiguration.
@@ -41,13 +43,13 @@ public class CustomConfigurationFactory extends ConfigurationFactory {
      * @return The Configuration.
      */
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
-        return new CustomConfiguration(source);
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
+        return new CustomConfiguration(loggerContext, source);
     }
 
     @Override
-    public Configuration getConfiguration(final String name, final URI configLocation) {
-        return new CustomConfiguration();
+    public Configuration getConfiguration(LoggerContext loggerContext, final String name, final URI configLocation) {
+        return new CustomConfiguration(loggerContext);
     }
 
     /**


[16/18] logging-log4j2 git commit: [LOG4J2-1547] The Core AbstractConfiguration should track its LoggerContext.

Posted by gg...@apache.org.
[LOG4J2-1547] The Core AbstractConfiguration should track its
LoggerContext.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/322ccf0f
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/322ccf0f
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/322ccf0f

Branch: refs/heads/LOG4J2-1539
Commit: 322ccf0f63128ac2f08db2d1bdb5e93bd6cb8f49
Parents: acbecc0
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 14:37:24 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 14:37:24 2016 -0700

----------------------------------------------------------------------
 .../org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java  | 4 ++--
 .../apache/logging/log4j/core/config/AbstractConfiguration.java  | 3 ++-
 .../logging/log4j/core/config/plugins/util/ResolverUtilTest.java | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/322ccf0f/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 667bac2..ea55dd9 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -53,8 +53,8 @@ public class Log4j1ConfigurationFactoryTest {
     private Layout<?> testFile(final String configResource) throws Exception {
         final URL configLocation = ClassLoader.getSystemResource(configResource);
         assertNotNull(configLocation);
-        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration("test",
-                configLocation.toURI());
+        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration(null,
+        		"test", configLocation.toURI());
         assertNotNull(configuration);
         final FileAppender appender = configuration.getAppender("File");
         assertNotNull(appender);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/322ccf0f/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index d452396..0e053a1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -131,7 +131,8 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
      */
     protected AbstractConfiguration(LoggerContext loggerContext, final ConfigurationSource configurationSource) {
         this.loggerContext = new WeakReference<>(loggerContext);
-        //this.loggerContext = new WeakReference(Objects.requireNonNull(loggerContext, "loggerContext is null"));
+        // The loggerContext is null for the NullConfiguration class.
+        // this.loggerContext = new WeakReference(Objects.requireNonNull(loggerContext, "loggerContext is null"));
         this.configurationSource = Objects.requireNonNull(configurationSource, "configurationSource is null");
         componentMap.put(Configuration.CONTEXT_PROPERTIES, properties);
         pluginManager = new PluginManager(Node.CATEGORY);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/322ccf0f/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
index f5d13eb..c0f1e3a 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
@@ -200,7 +200,7 @@ public class ResolverUtilTest {
     static void createJar(URI jarURI, File workDir, File f) throws Exception {
         Map<String, String> env = new HashMap<>(); 
         env.put("create", "true");
-        URI uri = URI.create("jar:file://" + jarURI.getPath());
+        URI uri = URI.create("jar:file://" + jarURI.getRawPath());
         try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {   
             Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString());
             if (path.getParent() != null) {


[07/18] logging-log4j2 git commit: [LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not supported. Another go around with a better set of tests from Pierrick HYMBERT.

Posted by gg...@apache.org.
[LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not
supported. Another go around with a better set of tests from Pierrick
HYMBERT.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/2d5812b2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/2d5812b2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/2d5812b2

Branch: refs/heads/LOG4J2-1539
Commit: 2d5812b2e98c2e1ca8e7acf322ae34aba34429c7
Parents: 33aaf3d
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:03:58 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:03:58 2016 -0700

----------------------------------------------------------------------
 .../core/config/plugins/util/ResolverUtil.java  |  11 +-
 .../plugins/util/PluginManagerPackagesTest.java |   2 +-
 .../util/ResolverUtilCustomProtocolTest.java    | 227 +++++++++++++++++++
 .../config/plugins/util/ResolverUtilTest.java   | 146 +++++++-----
 4 files changed, 322 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d5812b2/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
index 14bf1e8..a353228 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtil.java
@@ -199,9 +199,14 @@ public class ResolverUtil {
                         close(stream, newURL);
                     }
                 } else if (VFS.equals(url.getProtocol())) {
-                    final String path = urlPath.substring(1, urlPath.length() - packageName.length() - 2);
-                    final File file = new File(path);
-                    loadImplementationsInJar(test, packageName, file);
+                    final String containerPath = urlPath.substring(1,
+                                                  urlPath.length() - packageName.length() - 2);
+                    final File containerFile = new File(containerPath);
+                    if (containerFile.isDirectory()) {
+                        loadImplementationsInDirectory(test, packageName, new File(containerFile, packageName));
+                    } else {
+                        loadImplementationsInJar(test, packageName, containerFile);
+                    }
                 } else if (BUNDLE_RESOURCE.equals(url.getProtocol())) {
                     loadImplementationsInBundle(test, packageName);
                 } else {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d5812b2/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
index 5808b10..c97643f 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/PluginManagerPackagesTest.java
@@ -85,7 +85,7 @@ public class PluginManagerPackagesTest {
         assertEquals("abc123XYZ", messages.get(0));
     }
 
-    private void compile(final File f) throws IOException {
+    static void compile(final File f) throws IOException {
         // set up compiler
         final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
         final DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d5812b2/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
new file mode 100644
index 0000000..86bc000
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.core.config.plugins.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.apache.logging.log4j.core.config.plugins.util.ResolverUtilTest.compileAndCreateClassLoader;
+import static org.apache.logging.log4j.core.config.plugins.util.ResolverUtilTest.compileJarAndCreateClassLoader;
+
+import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.PluginTest;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+/**
+ * Tests the ResolverUtil class for custom protocol like bundleresource, vfs, vfszip.
+ */
+public class ResolverUtilCustomProtocolTest {
+
+    static class NoopURLStreamHandlerFactory implements URLStreamHandlerFactory {
+        @Override
+        public URLStreamHandler createURLStreamHandler(String protocol) {
+            return new URLStreamHandler() {
+                @Override
+                protected URLConnection openConnection(URL url) {
+                    return open(url, null);
+                }
+
+                private URLConnection open(URL url, Proxy proxy) {
+                    return new URLConnection(url) {
+                        @Override
+                        public void connect() throws IOException {
+                            // do nothing
+                        }
+                    };
+                }
+
+                @Override
+                protected URLConnection openConnection(URL url, Proxy proxy) {
+                    return open(url, proxy);
+                }
+
+                @Override
+                protected int getDefaultPort() {
+                    return 1;
+                }
+            };
+        }
+    }
+
+    static class SingleURLClassLoader extends ClassLoader {
+        private URL url;
+
+        public SingleURLClassLoader(URL url) {
+            this.url = url;
+        }
+
+        public SingleURLClassLoader(URL url, ClassLoader parent) {
+            super(parent);
+            this.url = url;
+        }
+
+        @Override
+        protected URL findResource(String name) {
+            return url;
+        }
+
+        @Override
+        public URL getResource(String name) {
+            return findResource(name);
+        }
+
+        @Override
+        public Enumeration<URL> getResources(String name) throws IOException {
+            return findResources(name);
+        }
+
+        @Override
+        protected Enumeration<URL> findResources(String name) throws IOException {
+            return Collections.enumeration(Arrays.asList(findResource(name)));
+        }
+    }
+
+    @BeforeClass
+    public static void defineURLHandler() {
+        URL.setURLStreamHandlerFactory(new NoopURLStreamHandlerFactory());
+    }
+
+    @AfterClass
+    public static void removeURLHandler() throws Exception {
+        // Simulate this - Not the best way, but no other choice welcome ?
+        // URL.setURLStreamHandlerFactory(null);
+        Field handlersFields = URL.class.getDeclaredField("handlers");
+        if (!handlersFields.isAccessible()) {
+            handlersFields.setAccessible(true);
+        }
+        Field factoryFields = URL.class.getDeclaredField("factory");
+        if (!factoryFields.isAccessible()) {
+            factoryFields.setAccessible(true);
+        }
+
+        @SuppressWarnings("unchecked")
+        Hashtable<String, URLStreamHandler> handlers = (Hashtable<String, URLStreamHandler>) handlersFields.get(null);
+        handlers.clear();
+        factoryFields.set(null, null);
+    }
+
+    @Test
+    public void testExtractPathFromVfsEarJarWindowsUrl() throws Exception {
+        final URL url = new URL(
+                "vfs:/C:/jboss/jboss-eap-6.4/standalone/deployments/com.xxx.yyy.application-ear.ear/lib/com.xxx.yyy.logging.jar/com/xxx/yyy/logging/config/");
+        final String expected = "/C:/jboss/jboss-eap-6.4/standalone/deployments/com.xxx.yyy.application-ear.ear/lib/com.xxx.yyy.logging.jar/com/xxx/yyy/logging/config/";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfsWarClassesWindowsUrl() throws Exception {
+        final URL url = new URL(
+                "vfs:/C:/jboss/jboss-eap-6.4/standalone/deployments/test-log4j2-web-standalone.war/WEB-INF/classes/org/hypik/test/jboss/eap7/logging/config/");
+        final String expected = "/C:/jboss/jboss-eap-6.4/standalone/deployments/test-log4j2-web-standalone.war/WEB-INF/classes/org/hypik/test/jboss/eap7/logging/config/";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfsWarClassesLinuxUrl() throws Exception {
+        final URL url = new URL(
+                "vfs:/content/mycustomweb.war/WEB-INF/classes/org/hypik/test/jboss/log4j2/logging/pluginweb/");
+        final String expected = "/content/mycustomweb.war/WEB-INF/classes/org/hypik/test/jboss/log4j2/logging/pluginweb/";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfszipUrl() throws Exception {
+        final URL url = new URL(
+                "vfszip:/home2/jboss-5.0.1.CR2/jboss-as/server/ais/ais-deploy/myear.ear/mywar.war/WEB-INF/some.xsd");
+        final String expected = "/home2/jboss-5.0.1.CR2/jboss-as/server/ais/ais-deploy/myear.ear/mywar.war/WEB-INF/some.xsd";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfsEarJarLinuxUrl() throws Exception {
+        final URL url = new URL(
+                "vfs:/content/test-log4k2-ear.ear/lib/test-log4j2-jar-plugins.jar/org/hypik/test/jboss/log4j2/pluginjar/");
+        final String expected = "/content/test-log4k2-ear.ear/lib/test-log4j2-jar-plugins.jar/org/hypik/test/jboss/log4j2/pluginjar/";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfszipUrlWithPlusCharacters() throws Exception {
+        final URL url = new URL("vfszip:/path+with+plus/file+name+with+plus.xml");
+        final String expected = "/path+with+plus/file+name+with+plus.xml";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromVfsUrlWithPlusCharacters() throws Exception {
+        final URL url = new URL("vfs:/path+with+plus/file+name+with+plus.xml");
+        final String expected = "/path+with+plus/file+name+with+plus.xml";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromResourceBundleUrl() throws Exception {
+        final URL url = new URL("bundleresource:/some/path/some/file.properties");
+        final String expected = "/some/path/some/file.properties";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testExtractPathFromResourceBundleUrlWithPlusCharacters() throws Exception {
+        final URL url = new URL("bundleresource:/some+path/some+file.properties");
+        final String expected = "/some+path/some+file.properties";
+        assertEquals(expected, new ResolverUtil().extractPath(url));
+    }
+
+    @Test
+    public void testFindInPackageFromVfsDirectoryURL() throws Exception {
+        ClassLoader cl = compileAndCreateClassLoader("3");
+
+        ResolverUtil resolverUtil = new ResolverUtil();
+        resolverUtil.setClassLoader(new SingleURLClassLoader(new URL("vfs:/target/resolverutil3/customplugin3/"), cl));
+        resolverUtil.findInPackage(new PluginTest(), "customplugin3");
+        assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+        assertEquals("Unexpected class resolved", cl.loadClass("customplugin3.FixedString3Layout"),
+                resolverUtil.getClasses().iterator().next());
+    }
+
+    @Test
+    public void testFindInPackageFromVfsJarURL() throws Exception {
+        ClassLoader cl = compileJarAndCreateClassLoader("4");
+
+        ResolverUtil resolverUtil = new ResolverUtil();
+        resolverUtil.setClassLoader(
+                new SingleURLClassLoader(new URL("vfs:/target/resolverutil4/customplugin4.jar/customplugin4/"), cl));
+        resolverUtil.findInPackage(new PluginTest(), "customplugin4");
+        assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+        assertEquals("Unexpected class resolved", cl.loadClass("customplugin4.FixedString4Layout"),
+                resolverUtil.getClasses().iterator().next());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/2d5812b2/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
index cbcd23c..76ab740 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
@@ -20,12 +20,23 @@ package org.apache.logging.log4j.core.config.plugins.util;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.io.File;
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
+import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
-
-import org.junit.Ignore;
+import java.net.URLClassLoader;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.PluginTest;
 import org.junit.Test;
 
 /**
@@ -93,64 +104,6 @@ public class ResolverUtilTest {
         assertEquals(expected, new ResolverUtil().extractPath(url));
     }
 
-    @Ignore
-    @Test
-    public void testExtractPathFromVfszipUrl() throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL(
-                "vfszip:/home2/jboss-5.0.1.CR2/jboss-as/server/ais/ais-deploy/myear.ear/mywar.war/WEB-INF/some.xsd");
-        final String expected = "/home2/jboss-5.0.1.CR2/jboss-as/server/ais/ais-deploy/myear.ear/mywar.war/WEB-INF/some.xsd";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
-    @Ignore
-    @Test
-    public void testExtractPathFromVfsUrl() throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL(
-                "vfs:/C:/jboss/jboss-eap-6.4/standalone/deployments/com.xxx.yyy.application-ear.ear/lib/com.xxx.yyy.logging.jar/com/xxx/yyy/logging/config/");
-        final String expected = "/jboss/jboss-eap-6.4/standalone/deployments/com.xxx.yyy.application-ear.ear/lib/com.xxx.yyy.logging.jar/com/xxx/yyy/logging/config/";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
-    @Ignore
-    @Test
-    public void testExtractPathFromVfszipUrlWithPlusCharacters()
-            throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL("vfszip:/path+with+plus/file+name+with+plus.xml");
-        final String expected = "/path+with+plus/file+name+with+plus.xml";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
-    @Ignore
-    @Test
-    public void testExtractPathFromVfsUrlWithPlusCharacters()
-            throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL("vfs:/path+with+plus/file+name+with+plus.xml");
-        final String expected = "/path+with+plus/file+name+with+plus.xml";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
-    @Ignore
-    @Test
-    public void testExtractPathFromResourceBundleUrl() throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL("resourcebundle:/some/path/some/file.properties");
-        final String expected = "/some/path/some/file.properties";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
-    @Ignore
-    @Test
-    public void testExtractPathFromResourceBundleUrlWithPlusCharacters() throws Exception {
-        // need to install URLStreamHandlerFactory to prevent "unknown protocol" MalformedURLException
-        final URL url = new URL("resourcebundle:/some+path/some+file.properties");
-        final String expected = "/some+path/some+file.properties";
-        assertEquals(expected, new ResolverUtil().extractPath(url));
-    }
-
     @Test
     public void testExtractPathFromHttpUrl() throws Exception {
         final URL url = new URL("http://java.sun.com/index.html#chapter1");
@@ -186,4 +139,77 @@ public class ResolverUtilTest {
         assertEquals(expected, new ResolverUtil().extractPath(url));
     }
 
+    @Test
+    public void testFindInPackageFromDirectoryPath() throws Exception {
+      ClassLoader cl = compileAndCreateClassLoader("1");
+
+      ResolverUtil resolverUtil = new ResolverUtil();
+      resolverUtil.setClassLoader(cl);
+      resolverUtil.findInPackage(new PluginTest(), "customplugin1");
+      assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+      assertEquals("Unexpected class resolved",
+            cl.loadClass("customplugin1.FixedString1Layout"),
+            resolverUtil.getClasses().iterator().next());
+    }
+
+    @Test
+    public void testFindInPackageFromJarPath() throws Exception {
+      ClassLoader cl = compileJarAndCreateClassLoader("2");
+
+      ResolverUtil resolverUtil = new ResolverUtil();
+      resolverUtil.setClassLoader(cl);
+      resolverUtil.findInPackage(new PluginTest(), "customplugin2");
+      assertEquals("Class not found in packages", 1, resolverUtil.getClasses().size());
+      assertEquals("Unexpected class resolved",
+            cl.loadClass("customplugin2.FixedString2Layout"),
+            resolverUtil.getClasses().iterator().next());
+    }
+
+    static URLClassLoader compileJarAndCreateClassLoader(String suffix) throws IOException, Exception {
+        File workDir = compile(suffix);
+        File jarFile = new File(workDir, "customplugin" + suffix + ".jar");
+        URI jarURL = jarFile.toURI();
+        createJar(jarURL, workDir, new File(workDir,
+              "customplugin" + suffix + "/FixedString" + suffix + "Layout.class"));
+        return URLClassLoader.newInstance(new URL[] {jarURL.toURL()});
+    }
+
+    static URLClassLoader compileAndCreateClassLoader(String suffix) throws IOException {
+        final File workDir = compile(suffix);
+        return URLClassLoader.newInstance(new URL[] {workDir.toURI().toURL()});
+    }
+
+    static File compile(String suffix) throws IOException {
+        final File orig = new File("target/test-classes/customplugin/FixedStringLayout.java.source");
+        final File workDir = new File("target/resolverutil" + suffix);
+        final File javaFile = new File(workDir, "customplugin" + suffix + "/FixedString" + suffix + "Layout.java");
+        final File parent = javaFile.getParentFile();
+        if (!parent.exists()) {
+          assertTrue("Create customplugin" + suffix + " folder KO", javaFile.getParentFile().mkdirs());
+        }
+  
+        String content = new String(Files.readAllBytes(orig.toPath()))
+          .replaceAll("FixedString", "FixedString" + suffix)
+          .replaceAll("customplugin", "customplugin" + suffix);
+        Files.write(javaFile.toPath(), content.getBytes());
+  
+        PluginManagerPackagesTest.compile(javaFile);
+        return workDir;
+    }
+
+    static void createJar(URI jarURL, File workDir, File f) throws Exception {
+        Map<String, String> env = new HashMap<>(); 
+        env.put("create", "true");
+        URI uri = URI.create("jar:file://" + jarURL.getPath());
+        try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {   
+            Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString());
+            if (path.getParent() != null) {
+                Files.createDirectories(path.getParent());
+            }
+            Files.copy(f.toPath(),
+                   path, 
+                   StandardCopyOption.REPLACE_EXISTING ); 
+        } 
+    }
+
 }


[14/18] logging-log4j2 git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Posted by gg...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/logging-log4j2.git

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/1db38fc4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/1db38fc4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/1db38fc4

Branch: refs/heads/LOG4J2-1539
Commit: 1db38fc42fac86f8da408e5450b0b3069ffe5caa
Parents: e15d0c7 cc0bf0b
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:52:41 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:52:41 2016 -0700

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java | 210 +++++++++++--------
 .../config/Log4j1ConfigurationFactoryTest.java  |  25 ++-
 ...g4j-console-EnhancedPatternLayout.properties |   1 -
 .../log4j-console-HtmlLayout.properties         |   1 -
 .../log4j-console-PatternLayout.properties      |   1 -
 .../log4j-console-SimpleLayout.properties       |   1 -
 .../log4j-console-TTCCLayout.properties         |   1 -
 .../log4j-console-XmlLayout.properties          |   1 -
 .../log4j-file-SimpleLayout.properties          |  17 ++
 9 files changed, 158 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/1db38fc4/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------


[12/18] logging-log4j2 git commit: Support FileAppender

Posted by gg...@apache.org.
Support FileAppender


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/3aceb2a3
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/3aceb2a3
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/3aceb2a3

Branch: refs/heads/LOG4J2-1539
Commit: 3aceb2a327bdade228ec15662bce4cf541f82239
Parents: fadd676
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Thu Aug 25 22:29:08 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Thu Aug 25 22:29:08 2016 +0200

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java | 48 ++++++++++++++++++--
 .../config/Log4j1ConfigurationFactoryTest.java  | 25 +++++++++-
 ...g4j-console-EnhancedPatternLayout.properties |  1 -
 .../log4j-console-HtmlLayout.properties         |  1 -
 .../log4j-console-PatternLayout.properties      |  1 -
 .../log4j-console-SimpleLayout.properties       |  1 -
 .../log4j-console-TTCCLayout.properties         |  1 -
 .../log4j-console-XmlLayout.properties          |  1 -
 .../log4j-file-SimpleLayout.properties          | 17 +++++++
 9 files changed, 83 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
index 11f7f76..84b8533 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
@@ -19,6 +19,7 @@ package org.apache.log4j.config;
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
 import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
@@ -126,6 +127,9 @@ public class Log4j1ConfigurationParser {
         case "org.apache.log4j.ConsoleAppender":
             buildConsoleAppender(appenderName);
             break;
+        case "org.apache.log4j.FileAppender":
+            buildFileAppender(appenderName);
+            break;
         default:
             reportWarning("Unknown appender class: " + appenderClass + "; ignoring appender: " + appenderName);
         }
@@ -151,16 +155,46 @@ public class Log4j1ConfigurationParser {
                 appenderBuilder.addAttribute("target", target);
             }
         }
-        buildAppenderAttribute(appenderName, appenderBuilder, "Follow", "false", "follow");
+        buildAttribute(appenderName, appenderBuilder, "Follow", "follow");
+        if ("false".equalsIgnoreCase(getLog4jAppenderValue(appenderName, "ImmediateFlush"))) {
+            reportWarning("ImmediateFlush=false is not supported on Console appender");
+        }
         buildAppenderLayout(appenderName, appenderBuilder);
         builder.add(appenderBuilder);
     }
 
-    private void buildAppenderAttribute(String appenderName, AppenderComponentBuilder appenderBuilder,
-                                        String sourceAttributeName, String defaultValue, String targetAttributeName) {
-        final String attributeValue = getLog4jAppenderValue(appenderName, sourceAttributeName, defaultValue);
+    private void buildFileAppender(final String appenderName) {
+        final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, "File");
+        buildMandatoryAttribute(appenderName, appenderBuilder, "File", "fileName");
+        buildAttribute(appenderName, appenderBuilder, "Append", "append");
+        buildAttribute(appenderName, appenderBuilder, "BufferedIO", "bufferedIo");
+        buildAttribute(appenderName, appenderBuilder, "BufferSize", "bufferSize");
+        buildAttribute(appenderName, appenderBuilder, "ImmediateFlush", "immediateFlush");
+        buildAppenderLayout(appenderName, appenderBuilder);
+        builder.add(appenderBuilder);
+    }
+
+    private void buildAttribute(String componentName, ComponentBuilder componentBuilder,
+                                String sourceAttributeName, String targetAttributeName) {
+        final String attributeValue = getLog4jAppenderValue(componentName, sourceAttributeName);
+        if (attributeValue != null) {
+            componentBuilder.addAttribute(targetAttributeName, attributeValue);
+        }
+    }
+
+    private void buildAttributeWithDefault(String componentName, ComponentBuilder componentBuilder,
+                                           String sourceAttributeName, String targetAttributeName, String defaultValue) {
+        final String attributeValue = getLog4jAppenderValue(componentName, sourceAttributeName, defaultValue);
+        componentBuilder.addAttribute(targetAttributeName, attributeValue);
+    }
+
+    private void buildMandatoryAttribute(String componentName, ComponentBuilder componentBuilder,
+                                         String sourceAttributeName, String targetAttributeName) {
+        final String attributeValue = getLog4jAppenderValue(componentName, sourceAttributeName);
         if (attributeValue != null) {
-            appenderBuilder.addAttribute(targetAttributeName, attributeValue);
+            componentBuilder.addAttribute(targetAttributeName, attributeValue);
+        } else {
+            reportWarning("Missing " + sourceAttributeName + " for " + componentName);
         }
     }
 
@@ -273,6 +307,10 @@ public class Log4j1ConfigurationParser {
 
     }
 
+    private String getLog4jAppenderValue(final String appenderName, final String attributeName) {
+        return properties.getProperty("log4j.appender." + appenderName + "." + attributeName);
+    }
+
     private String getLog4jAppenderValue(final String appenderName, final String attributeName,
                                          final String defaultValue) {
         return properties.getProperty("log4j.appender." + appenderName + "." + attributeName, defaultValue);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 9f34563..43d7b14 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -23,6 +23,7 @@ import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.appender.ConsoleAppender.Target;
+import org.apache.logging.log4j.core.appender.FileAppender;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.core.layout.HtmlLayout;
@@ -41,8 +42,6 @@ public class Log4j1ConfigurationFactoryTest {
         assertNotNull(configuration);
         final ConsoleAppender appender = configuration.getAppender("Console");
         assertNotNull(appender);
-        // Can't set ImmediateFlush for a Console Appender in Log4j 2 like you can in 1.2
-        assertTrue(appender.getImmediateFlush());
         assertEquals(Target.SYSTEM_ERR, appender.getTarget());
         //
         final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
@@ -51,6 +50,22 @@ public class Log4j1ConfigurationFactoryTest {
         return appender.getLayout();
     }
 
+    private Layout<?> testFile(final String configResource) throws Exception {
+        final URL configLocation = ClassLoader.getSystemResource(configResource);
+        assertNotNull(configLocation);
+        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration("test",
+                configLocation.toURI());
+        assertNotNull(configuration);
+        final FileAppender appender = configuration.getAppender("File");
+        assertNotNull(appender);
+        assertEquals("target/mylog.txt", appender.getFileName());
+        //
+        final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
+        assertNotNull(loggerConfig);
+        assertEquals(Level.DEBUG, loggerConfig.getLevel());
+        return appender.getLayout();
+    }
+
     @Test
     public void testConsoleEnhancedPatternLayout() throws Exception {
         final PatternLayout layout = (PatternLayout) testConsole("config-1.2/log4j-console-EnhancedPatternLayout.properties");
@@ -88,4 +103,10 @@ public class Log4j1ConfigurationFactoryTest {
         assertTrue(layout.isLocationInfo());
         assertFalse(layout.isProperties());
     }
+
+    @Test
+    public void testFileSimpleLayout() throws Exception {
+        final PatternLayout layout = (PatternLayout) testFile("config-1.2/log4j-file-SimpleLayout.properties");
+        assertEquals("%level - %m%n", layout.getConversionPattern());
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
index 01a4463..6793eb2 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-EnhancedPatternLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.EnhancedPatternLayout
 log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p %X %x: %m%n

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
index 304180c..216a12e 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-HtmlLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.HTMLLayout
 log4j.appender.Console.layout.Title=Headline

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
index fab7070..810a494 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-PatternLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.PatternLayout
 log4j.appender.Console.layout.ConversionPattern=%d{ISO8601} [%t][%c] %-5p: %m%n

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
index 5e915f8..5a8ac4e 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-SimpleLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.SimpleLayout
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
index 9f91789..80d38c2 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-TTCCLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.TTCCLayout
 log4j.appender.Console.layout.ThreadPrinting=true

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
index 96302a2..c8190ec 100644
--- a/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-console-XmlLayout.properties
@@ -11,7 +11,6 @@ log4j.rootLogger=TRACE, Console
 #
 
 log4j.appender.Console=org.apache.log4j.ConsoleAppender
-log4j.appender.Console.ImmediateFlush=false
 log4j.appender.Console.Target=System.err
 log4j.appender.Console.layout=org.apache.log4j.xml.XMLLayout
 log4j.appender.Console.layout.LocationInfo=true

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/3aceb2a3/log4j-1.2-api/src/test/resources/config-1.2/log4j-file-SimpleLayout.properties
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/resources/config-1.2/log4j-file-SimpleLayout.properties b/log4j-1.2-api/src/test/resources/config-1.2/log4j-file-SimpleLayout.properties
new file mode 100644
index 0000000..4d3ec0d
--- /dev/null
+++ b/log4j-1.2-api/src/test/resources/config-1.2/log4j-file-SimpleLayout.properties
@@ -0,0 +1,17 @@
+###############################################################################
+#
+# Log4J 1.2 Configuration.
+#
+
+log4j.rootLogger=TRACE, File
+
+##############################################################################
+#
+# The Console log
+#
+
+log4j.appender.File=org.apache.log4j.FileAppender
+log4j.appender.File.File=target/mylog.txt
+log4j.appender.File.layout=org.apache.log4j.SimpleLayout
+
+log4j.logger.com.example.foo = DEBUG


[09/18] logging-log4j2 git commit: [LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not supported. Create a JUnit Rule to manage the URLStreamHandlerFactory.

Posted by gg...@apache.org.
[LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not
supported. Create a JUnit Rule to manage the URLStreamHandlerFactory.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4157ef83
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4157ef83
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4157ef83

Branch: refs/heads/LOG4J2-1539
Commit: 4157ef83fa64899a1fcccc528456b03520261dde
Parents: 73323cd
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:15:45 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:15:45 2016 -0700

----------------------------------------------------------------------
 .../util/ResolverUtilCustomProtocolTest.java    | 41 +++------
 .../junit/URLStreamHandlerFactoryRule.java      | 96 ++++++++++++++++++++
 2 files changed, 107 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4157ef83/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
index 86bc000..532b9ef 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilCustomProtocolTest.java
@@ -17,14 +17,9 @@
 
 package org.apache.logging.log4j.core.config.plugins.util;
 
-import static org.junit.Assert.assertEquals;
 import static org.apache.logging.log4j.core.config.plugins.util.ResolverUtilTest.compileAndCreateClassLoader;
 import static org.apache.logging.log4j.core.config.plugins.util.ResolverUtilTest.compileJarAndCreateClassLoader;
-
-import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.PluginTest;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
@@ -38,12 +33,22 @@ import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Hashtable;
 
+import org.apache.logging.log4j.core.config.plugins.util.PluginRegistry.PluginTest;
+import org.apache.logging.log4j.junit.URLStreamHandlerFactoryRule;
+import org.junit.AfterClass;
+import org.junit.Rule;
+import org.junit.Test;
+
 /**
  * Tests the ResolverUtil class for custom protocol like bundleresource, vfs, vfszip.
  */
 public class ResolverUtilCustomProtocolTest {
 
+    @Rule
+    public URLStreamHandlerFactoryRule rule = new URLStreamHandlerFactoryRule(new NoopURLStreamHandlerFactory());
+
     static class NoopURLStreamHandlerFactory implements URLStreamHandlerFactory {
+        
         @Override
         public URLStreamHandler createURLStreamHandler(String protocol) {
             return new URLStreamHandler() {
@@ -107,30 +112,6 @@ public class ResolverUtilCustomProtocolTest {
         }
     }
 
-    @BeforeClass
-    public static void defineURLHandler() {
-        URL.setURLStreamHandlerFactory(new NoopURLStreamHandlerFactory());
-    }
-
-    @AfterClass
-    public static void removeURLHandler() throws Exception {
-        // Simulate this - Not the best way, but no other choice welcome ?
-        // URL.setURLStreamHandlerFactory(null);
-        Field handlersFields = URL.class.getDeclaredField("handlers");
-        if (!handlersFields.isAccessible()) {
-            handlersFields.setAccessible(true);
-        }
-        Field factoryFields = URL.class.getDeclaredField("factory");
-        if (!factoryFields.isAccessible()) {
-            factoryFields.setAccessible(true);
-        }
-
-        @SuppressWarnings("unchecked")
-        Hashtable<String, URLStreamHandler> handlers = (Hashtable<String, URLStreamHandler>) handlersFields.get(null);
-        handlers.clear();
-        factoryFields.set(null, null);
-    }
-
     @Test
     public void testExtractPathFromVfsEarJarWindowsUrl() throws Exception {
         final URL url = new URL(

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4157ef83/log4j-core/src/test/java/org/apache/logging/log4j/junit/URLStreamHandlerFactoryRule.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/junit/URLStreamHandlerFactoryRule.java b/log4j-core/src/test/java/org/apache/logging/log4j/junit/URLStreamHandlerFactoryRule.java
new file mode 100644
index 0000000..ac08bb3
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/junit/URLStreamHandlerFactoryRule.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+
+package org.apache.logging.log4j.junit;
+
+import java.lang.reflect.Field;
+import java.net.URL;
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+import java.util.Hashtable;
+
+import org.junit.Assert;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Installs and restores the URL URLStreamHandlerFactory before and after tests.
+ * <p>
+ * Might need tweaking for different JREs.
+ * </p>
+ */
+public class URLStreamHandlerFactoryRule implements TestRule {
+
+    public URLStreamHandlerFactoryRule() {
+        this(null);
+    }
+
+    public URLStreamHandlerFactoryRule(URLStreamHandlerFactory newURLStreamHandlerFactory) {
+        this.newURLStreamHandlerFactory = newURLStreamHandlerFactory;
+    }
+
+    private final URLStreamHandlerFactory newURLStreamHandlerFactory;
+
+    void clearURLHandlers() throws Exception {
+        Field handlersFields = URL.class.getDeclaredField("handlers");
+        if (handlersFields != null) {
+            if (!handlersFields.isAccessible()) {
+                handlersFields.setAccessible(true);
+            }
+            @SuppressWarnings("unchecked")
+            Hashtable<String, URLStreamHandler> handlers = (Hashtable<String, URLStreamHandler>) handlersFields
+                    .get(null);
+            if (handlers != null) {
+                handlers.clear();
+            }
+        }
+    }
+
+    @Override
+    public Statement apply(final Statement base, final Description description) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                Field factoryField = null;
+                int matches = 0;
+                URLStreamHandlerFactory oldFactory = null;
+                for (Field field : URL.class.getDeclaredFields()) {
+                    if (URLStreamHandlerFactory.class.equals(field.getType())) {
+                        factoryField = field;
+                        matches++;
+                        factoryField.setAccessible(true);
+                        oldFactory = (URLStreamHandlerFactory) factoryField.get(null);
+                        break;
+                    }
+                }
+                Assert.assertNotNull("java.net URL does not declare a java.net.URLStreamHandlerFactory field",
+                        factoryField);
+                Assert.assertEquals("java.net.URL declares multiple java.net.URLStreamHandlerFactory fields.", 1,
+                        matches);
+                URL.setURLStreamHandlerFactory(newURLStreamHandlerFactory);
+                try {
+                    base.evaluate();
+                } finally {
+                    clearURLHandlers();
+                    factoryField.set(null, null);
+                    URL.setURLStreamHandlerFactory(oldFactory);
+                }
+            }
+        };
+    }
+}


[17/18] logging-log4j2 git commit: [LOG4J2-1547] The Core AbstractConfiguration should track its LoggerContext and add Configuration.getLoggerContext(). Update changes.xml.

Posted by gg...@apache.org.
[LOG4J2-1547] The Core AbstractConfiguration should track its
LoggerContext and add Configuration.getLoggerContext(). Update
changes.xml.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/29e7bfd0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/29e7bfd0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/29e7bfd0

Branch: refs/heads/LOG4J2-1539
Commit: 29e7bfd0f230aad47dc852bac0464de9bd6f2316
Parents: 322ccf0
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 14:42:00 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 14:42:00 2016 -0700

----------------------------------------------------------------------
 src/changes/changes.xml | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/29e7bfd0/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c6e62dd..4c8303a 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -126,6 +126,9 @@
       <action issue="LOG4J2-1520" dev="ggregory" type="add" due-to="Gary Gregory">
         Add JUnit Rule implementations to manage the thread context.
       </action>
+      <action issue="LOG4J2-1547" dev="ggregory" type="add" due-to="Gary Gregory">
+        The Core AbstractConfiguration should track its LoggerContext and add Configuration.getLoggerContext().
+      </action>
       <action issue="LOG4J2-1458" dev="ggregory" type="update" due-to="Gary Gregory">
         Update Jackson from 2.7.5 to 2.8.0.
       </action>


[03/18] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master' into LOG4J2-1547-AbstractConfiguration-with-LoggerContext

Posted by gg...@apache.org.
Merge remote-tracking branch 'origin/master' into LOG4J2-1547-AbstractConfiguration-with-LoggerContext

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/56eba730
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/56eba730
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/56eba730

Branch: refs/heads/LOG4J2-1539
Commit: 56eba730fdc36beaab05f6e9077f752d138125f1
Parents: 85c5e81 30ea283
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Aug 23 21:12:00 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Aug 23 21:12:00 2016 -0700

----------------------------------------------------------------------
 .../core/config/AbstractConfiguration.java      | 26 ++++++++++----------
 1 file changed, 13 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/56eba730/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------


[02/18] logging-log4j2 git commit: First commit for branch for [LOG4J2-1547] The Core AbstractConfiguration should track its LoggerContext.

Posted by gg...@apache.org.
First commit for branch for [LOG4J2-1547]
The Core AbstractConfiguration should track its LoggerContext.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/85c5e81a
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/85c5e81a
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/85c5e81a

Branch: refs/heads/LOG4J2-1539
Commit: 85c5e81a4bca677bf02dc9be4f2dff3d1f0450c1
Parents: 24ebb9f
Author: Gary Gregory <gg...@apache.org>
Authored: Tue Aug 23 20:58:38 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Tue Aug 23 20:58:38 2016 -0700

----------------------------------------------------------------------
 .../config/Log4j1ConfigurationFactory.java      |    9 +-
 .../apache/log4j/BasicConfigurationFactory.java |   13 +-
 .../config/Log4j1ConfigurationFactoryTest.java  |    4 +-
 .../logging/log4j/core/LoggerContext.java       |    2 +-
 .../core/config/AbstractConfiguration.java      |   14 +-
 .../log4j/core/config/Configuration.java        |    8 +
 .../log4j/core/config/ConfigurationFactory.java | 1113 +++++++++---------
 .../log4j/core/config/DefaultConfiguration.java |    2 +-
 .../log4j/core/config/NullConfiguration.java    |    2 +-
 .../builder/api/ConfigurationBuilder.java       |    8 +
 .../config/builder/impl/BuiltConfiguration.java |    5 +-
 .../impl/DefaultConfigurationBuilder.java       |   29 +-
 .../composite/CompositeConfiguration.java       |    4 +-
 .../core/config/json/JsonConfiguration.java     |   14 +-
 .../config/json/JsonConfigurationFactory.java   |    5 +-
 .../properties/PropertiesConfiguration.java     |    8 +-
 .../PropertiesConfigurationBuilder.java         |   16 +-
 .../PropertiesConfigurationFactory.java         |   10 +-
 .../log4j/core/config/xml/XmlConfiguration.java |    7 +-
 .../config/xml/XmlConfigurationFactory.java     |    5 +-
 .../core/config/yaml/YamlConfiguration.java     |    7 +-
 .../config/yaml/YamlConfigurationFactory.java   |    5 +-
 .../log4j/core/impl/Log4jContextFactory.java    |    6 +-
 .../log4j/core/jmx/LoggerContextAdmin.java      |    4 +-
 .../core/net/server/AbstractSocketServer.java   |    7 +-
 .../log4j/core/BasicConfigurationFactory.java   |    6 +-
 .../log4j/core/config/ConfigurationTest.java    |    6 +
 .../builder/CustomConfigurationFactory.java     |   11 +-
 .../configuration/CustomConfiguration.java      |   13 +-
 .../CustomConfigurationFactory.java             |   12 +-
 30 files changed, 717 insertions(+), 638 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
index b1b2dfe..a974ed5 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationFactory.java
@@ -16,6 +16,10 @@
  */
 package org.apache.log4j.config;
 
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -23,9 +27,6 @@ import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
 import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
 
-import java.io.IOException;
-import java.io.InputStream;
-
 /**
  * Experimental ConfigurationFactory for Log4j 1.2 properties configuration files.
  */
@@ -39,7 +40,7 @@ public class Log4j1ConfigurationFactory extends ConfigurationFactory {
     private static final String[] SUFFIXES = {".properties"};
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
         final ConfigurationBuilder<BuiltConfiguration> builder;
         try (final InputStream configStream = source.getInputStream()) {
             builder = new Log4j1ConfigurationParser().buildConfigurationBuilder(configStream);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java b/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
index 49b2f82..aabc1c1 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/BasicConfigurationFactory.java
@@ -19,6 +19,7 @@ package org.apache.log4j;
 import java.net.URI;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.AbstractConfiguration;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
@@ -36,13 +37,13 @@ public class BasicConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
-        return new BasicConfiguration();
+    public Configuration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
+        return new BasicConfiguration(loggerContext);
     }
 
     @Override
-    public Configuration getConfiguration(final String name, final URI configLocation) {
-        return new BasicConfiguration();
+    public Configuration getConfiguration(LoggerContext loggerContext, final String name, final URI configLocation) {
+        return new BasicConfiguration(loggerContext);
     }
 
     public class BasicConfiguration extends AbstractConfiguration {
@@ -51,8 +52,8 @@ public class BasicConfigurationFactory extends ConfigurationFactory {
 
         private static final String DEFAULT_LEVEL = "org.apache.logging.log4j.level";
 
-        public BasicConfiguration() {
-            super(ConfigurationSource.NULL_SOURCE);
+        public BasicConfiguration(final LoggerContext loggerContext) {
+            super(loggerContext, ConfigurationSource.NULL_SOURCE);
 
             final LoggerConfig root = getRootLogger();
             setName("BasicConfiguration");

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
index 9f34563..c045415 100644
--- a/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
+++ b/log4j-1.2-api/src/test/java/org/apache/log4j/config/Log4j1ConfigurationFactoryTest.java
@@ -36,8 +36,8 @@ public class Log4j1ConfigurationFactoryTest {
     private Layout<?> testConsole(final String configResource) throws Exception {
         final URL configLocation = ClassLoader.getSystemResource(configResource);
         assertNotNull(configLocation);
-        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration("test",
-                configLocation.toURI());
+        final Configuration configuration = new Log4j1ConfigurationFactory().getConfiguration(null,
+                "test", configLocation.toURI());
         assertNotNull(configuration);
         final ConsoleAppender appender = configuration.getAppender("Console");
         assertNotNull(appender);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
index ce78615..7156b7c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
@@ -572,7 +572,7 @@ public class LoggerContext extends AbstractLifeCycle
         final ClassLoader cl = ClassLoader.class.isInstance(externalContext) ? (ClassLoader) externalContext : null;
         LOGGER.debug("Reconfiguration started for context[name={}] at URI {} ({}) with optional ClassLoader: {}",
                 contextName, configURI, this, cl);
-        final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(contextName, configURI, cl);
+        final Configuration instance = ConfigurationFactory.getInstance().getConfiguration(this, contextName, configURI, cl);
         if (instance == null) {
             LOGGER.error("Reconfiguration failed: No configuration found for '%s' at '%s' in '%s'", contextName, configURI, cl);
         } else {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
index bc42d1f..64ead88 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/AbstractConfiguration.java
@@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
+import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -39,6 +40,7 @@ import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.Layout;
 import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.appender.AsyncAppender;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.async.AsyncLoggerConfig;
@@ -122,11 +124,14 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
     private final WatchManager watchManager = new WatchManager(configurationScheduler);
     private AsyncLoggerConfigDisruptor asyncLoggerConfigDisruptor;
     private NanoClock nanoClock = new DummyNanoClock();
-
+    private WeakReference<LoggerContext> loggerContext;
+    
     /**
      * Constructor.
      */
-    protected AbstractConfiguration(final ConfigurationSource configurationSource) {
+    protected AbstractConfiguration(LoggerContext loggerContext, final ConfigurationSource configurationSource) {
+        this.loggerContext = new WeakReference<>(loggerContext);
+        //this.loggerContext = new WeakReference(Objects.requireNonNull(loggerContext, "loggerContext is null"));
         this.configurationSource = Objects.requireNonNull(configurationSource, "configurationSource is null");
         componentMap.put(Configuration.CONTEXT_PROPERTIES, properties);
         pluginManager = new PluginManager(Node.CATEGORY);
@@ -787,6 +792,11 @@ public abstract class AbstractConfiguration extends AbstractFilterable implement
         return root;
     }
 
+    @Override
+    public LoggerContext getLoggerContext() {
+        return loggerContext.get();
+    }
+    
     /**
      * Returns the root Logger.
      *

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
index 678242c..88be74d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/Configuration.java
@@ -24,6 +24,7 @@ import org.apache.logging.log4j.core.Appender;
 import org.apache.logging.log4j.core.Filter;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.async.AsyncLoggerConfigDelegate;
 import org.apache.logging.log4j.core.filter.Filterable;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
@@ -188,4 +189,11 @@ public interface Configuration extends Filterable {
      * @param nanoClock the new nano clock for this configuration. Must be non-null.
      */
     void setNanoClock(NanoClock nanoClock);
+
+    /**
+     * Gets the logger context.
+     * 
+     * @return the logger context.
+     */
+    LoggerContext getLoggerContext();
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
index 7452dfa..806451d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationFactory.java
@@ -1,553 +1,560 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache license, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the license for the specific language governing permissions and
- * limitations under the license.
- */
-package org.apache.logging.log4j.core.config;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.locks.Lock;
-import java.util.concurrent.locks.ReentrantLock;
-
-import org.apache.logging.log4j.Level;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
-import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
-import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
-import org.apache.logging.log4j.core.config.plugins.util.PluginType;
-import org.apache.logging.log4j.core.lookup.Interpolator;
-import org.apache.logging.log4j.core.lookup.StrSubstitutor;
-import org.apache.logging.log4j.core.util.FileUtils;
-import org.apache.logging.log4j.core.util.Loader;
-import org.apache.logging.log4j.core.util.NetUtils;
-import org.apache.logging.log4j.core.util.ReflectionUtil;
-import org.apache.logging.log4j.status.StatusLogger;
-import org.apache.logging.log4j.util.LoaderUtil;
-import org.apache.logging.log4j.util.PropertiesUtil;
-import org.apache.logging.log4j.util.Strings;
-
-/**
- * Factory class for parsed {@link Configuration} objects from a configuration file.
- * ConfigurationFactory allows the configuration implementation to be
- * dynamically chosen in 1 of 3 ways:
- * <ol>
- * <li>A system property named "log4j.configurationFactory" can be set with the
- * name of the ConfigurationFactory to be used.</li>
- * <li>
- * {@linkplain #setConfigurationFactory(ConfigurationFactory)} can be called
- * with the instance of the ConfigurationFactory to be used. This must be called
- * before any other calls to Log4j.</li>
- * <li>
- * A ConfigurationFactory implementation can be added to the classpath and configured as a plugin in the
- * {@link #CATEGORY ConfigurationFactory} category. The {@link Order} annotation should be used to configure the
- * factory to be the first one inspected. See
- * {@linkplain org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory} for an example.</li>
- * </ol>
- *
- * If the ConfigurationFactory that was added returns null on a call to
- * getConfiguration then any other ConfigurationFactories found as plugins will
- * be called in their respective order. DefaultConfiguration is always called
- * last if no configuration has been returned.
- */
-public abstract class ConfigurationFactory extends ConfigurationBuilderFactory {
-    
-    /**
-     * Allows the ConfigurationFactory class to be specified as a system property.
-     */
-    public static final String CONFIGURATION_FACTORY_PROPERTY = "log4j.configurationFactory";
-
-    /**
-     * Allows the location of the configuration file to be specified as a system property.
-     */
-    public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
-
-    /**
-     * Plugin category used to inject a ConfigurationFactory {@link org.apache.logging.log4j.core.config.plugins.Plugin}
-     * class.
-     *
-     * @since 2.1
-     */
-    public static final String CATEGORY = "ConfigurationFactory";
-
-    /**
-     * Allows subclasses access to the status logger without creating another instance.
-     */
-    protected static final Logger LOGGER = StatusLogger.getLogger();
-
-    /**
-     * File name prefix for test configurations.
-     */
-    protected static final String TEST_PREFIX = "log4j2-test";
-
-    /**
-     * File name prefix for standard configurations.
-     */
-    protected static final String DEFAULT_PREFIX = "log4j2";
-
-    /**
-     * The name of the classloader URI scheme.
-     */
-    private static final String CLASS_LOADER_SCHEME = "classloader";
-
-    /**
-     * The name of the classpath URI scheme, synonymous with the classloader URI scheme.
-     */
-    private static final String CLASS_PATH_SCHEME = "classpath";
-
-    private static volatile List<ConfigurationFactory> factories = null;
-
-    private static ConfigurationFactory configFactory = new Factory();
-
-    protected final StrSubstitutor substitutor = new StrSubstitutor(new Interpolator());
-
-    private static final Lock LOCK = new ReentrantLock();
-
-    /**
-     * Returns the ConfigurationFactory.
-     * @return the ConfigurationFactory.
-     */
-    public static ConfigurationFactory getInstance() {
-        // volatile works in Java 1.6+, so double-checked locking also works properly
-        //noinspection DoubleCheckedLocking
-        if (factories == null) {
-            LOCK.lock();
-            try {
-                if (factories == null) {
-                    final List<ConfigurationFactory> list = new ArrayList<>();
-                    final String factoryClass = PropertiesUtil.getProperties().getStringProperty(CONFIGURATION_FACTORY_PROPERTY);
-                    if (factoryClass != null) {
-                        addFactory(list, factoryClass);
-                    }
-                    final PluginManager manager = new PluginManager(CATEGORY);
-                    manager.collectPlugins();
-                    final Map<String, PluginType<?>> plugins = manager.getPlugins();
-                    final List<Class<? extends ConfigurationFactory>> ordered = new ArrayList<>(plugins.size());
-                    for (final PluginType<?> type : plugins.values()) {
-                        try {
-                            ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class));
-                        } catch (final Exception ex) {
-                            LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex);
-                        }
-                    }
-                    Collections.sort(ordered, OrderComparator.getInstance());
-                    for (final Class<? extends ConfigurationFactory> clazz : ordered) {
-                        addFactory(list, clazz);
-                    }
-                    // see above comments about double-checked locking
-                    //noinspection NonThreadSafeLazyInitialization
-                    factories = Collections.unmodifiableList(list);
-                }
-            } finally {
-                LOCK.unlock();
-            }
-        }
-
-        LOGGER.debug("Using configurationFactory {}", configFactory);
-        return configFactory;
-    }
-
-    private static void addFactory(final Collection<ConfigurationFactory> list, final String factoryClass) {
-        try {
-            addFactory(list, LoaderUtil.loadClass(factoryClass).asSubclass(ConfigurationFactory.class));
-        } catch (final Exception ex) {
-            LOGGER.error("Unable to load class {}", factoryClass, ex);
-        }
-    }
-
-    private static void addFactory(final Collection<ConfigurationFactory> list,
-                                   final Class<? extends ConfigurationFactory> factoryClass) {
-        try {
-            list.add(ReflectionUtil.instantiate(factoryClass));
-        } catch (final Exception ex) {
-            LOGGER.error("Unable to create instance of {}", factoryClass.getName(), ex);
-        }
-    }
-
-    /**
-     * Sets the configuration factory. This method is not intended for general use and may not be thread safe.
-     * @param factory the ConfigurationFactory.
-     */
-    public static void setConfigurationFactory(final ConfigurationFactory factory) {
-        configFactory = factory;
-    }
-
-    /**
-     * Resets the ConfigurationFactory to the default. This method is not intended for general use and may
-     * not be thread safe.
-     */
-    public static void resetConfigurationFactory() {
-        configFactory = new Factory();
-    }
-
-    /**
-     * Removes the ConfigurationFactory. This method is not intended for general use and may not be thread safe.
-     * @param factory The factory to remove.
-     */
-    public static void removeConfigurationFactory(final ConfigurationFactory factory) {
-        if (configFactory == factory) {
-            configFactory = new Factory();
-        }
-    }
-
-    protected abstract String[] getSupportedTypes();
-
-    protected boolean isActive() {
-        return true;
-    }
-
-    public abstract Configuration getConfiguration(ConfigurationSource source);
-
-    /**
-     * Returns the Configuration.
-     * @param name The configuration name.
-     * @param configLocation The configuration location.
-     * @return The Configuration.
-     */
-    public Configuration getConfiguration(final String name, final URI configLocation) {
-        if (!isActive()) {
-            return null;
-        }
-        if (configLocation != null) {
-            final ConfigurationSource source = getInputFromUri(configLocation);
-            if (source != null) {
-                return getConfiguration(source);
-            }
-        }
-        return null;
-    }
-
-    /**
-     * Returns the Configuration obtained using a given ClassLoader.
-     *
-     * @param name The configuration name.
-     * @param configLocation A URI representing the location of the configuration.
-     * @param loader The default ClassLoader to use. If this is {@code null}, then the
-     *               {@linkplain LoaderUtil#getThreadContextClassLoader() default ClassLoader} will be used.
-     * @return The Configuration.
-     * @since 2.1
-     */
-    public Configuration getConfiguration(final String name, final URI configLocation, final ClassLoader loader) {
-        if (!isActive()) {
-            return null;
-        }
-        if (loader == null) {
-            return getConfiguration(name, configLocation);
-        }
-        if (isClassLoaderUri(configLocation)) {
-            final String path = extractClassLoaderUriPath(configLocation);
-            final ConfigurationSource source = getInputFromResource(path, loader);
-            if (source != null) {
-                final Configuration configuration = getConfiguration(source);
-                if (configuration != null) {
-                    return configuration;
-                }
-            }
-        }
-        return getConfiguration(name, configLocation);
-    }
-
-    /**
-     * Loads the configuration from a URI.
-     * @param configLocation A URI representing the location of the configuration.
-     * @return The ConfigurationSource for the configuration.
-     */
-    protected ConfigurationSource getInputFromUri(final URI configLocation) {
-        final File configFile = FileUtils.fileFromUri(configLocation);
-        if (configFile != null && configFile.exists() && configFile.canRead()) {
-            try {
-                return new ConfigurationSource(new FileInputStream(configFile), configFile);
-            } catch (final FileNotFoundException ex) {
-                LOGGER.error("Cannot locate file {}", configLocation.getPath(), ex);
-            }
-        }
-        if (isClassLoaderUri(configLocation)) {
-            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
-            final String path = extractClassLoaderUriPath(configLocation);
-            final ConfigurationSource source = getInputFromResource(path, loader);
-            if (source != null) {
-                return source;
-            }
-        }
-        if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing error message thrown by uri.toURL()
-            LOGGER.error("File not found in file system or classpath: {}", configLocation.toString());
-            return null;
-        }
-        try {
-            return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL());
-        } catch (final MalformedURLException ex) {
-            LOGGER.error("Invalid URL {}", configLocation.toString(), ex);
-        } catch (final Exception ex) {
-            LOGGER.error("Unable to access {}", configLocation.toString(), ex);
-        }
-        return null;
-    }
-
-    private static boolean isClassLoaderUri(final URI uri) {
-        if (uri == null) {
-            return false;
-        }
-        final String scheme = uri.getScheme();
-        return scheme == null || scheme.equals(CLASS_LOADER_SCHEME) || scheme.equals(CLASS_PATH_SCHEME);
-    }
-
-    private static String extractClassLoaderUriPath(final URI uri) {
-        return uri.getScheme() == null ? uri.getPath() : uri.getSchemeSpecificPart();
-    }
-
-    /**
-     * Loads the configuration from the location represented by the String.
-     * @param config The configuration location.
-     * @param loader The default ClassLoader to use.
-     * @return The InputSource to use to read the configuration.
-     */
-    protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
-        try {
-            final URL url = new URL(config);
-            return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
-        } catch (final Exception ex) {
-            final ConfigurationSource source = getInputFromResource(config, loader);
-            if (source == null) {
-                try {
-                    final File file = new File(config);
-                    return new ConfigurationSource(new FileInputStream(file), file);
-                } catch (final FileNotFoundException fnfe) {
-                    // Ignore the exception
-                    LOGGER.catching(Level.DEBUG, fnfe);
-                }
-            }
-            return source;
-        }
-    }
-
-    /**
-     * Retrieves the configuration via the ClassLoader.
-     * @param resource The resource to load.
-     * @param loader The default ClassLoader to use.
-     * @return The ConfigurationSource for the configuration.
-     */
-    protected ConfigurationSource getInputFromResource(final String resource, final ClassLoader loader) {
-        final URL url = Loader.getResource(resource, loader);
-        if (url == null) {
-            return null;
-        }
-        InputStream is = null;
-        try {
-            is = url.openStream();
-        } catch (final IOException ioe) {
-            LOGGER.catching(Level.DEBUG, ioe);
-            return null;
-        }
-        if (is == null) {
-            return null;
-        }
-
-        if (FileUtils.isFile(url)) {
-            try {
-                return new ConfigurationSource(is, FileUtils.fileFromUri(url.toURI()));
-            } catch (final URISyntaxException ex) {
-                // Just ignore the exception.
-                LOGGER.catching(Level.DEBUG, ex);
-            }
-        }
-        return new ConfigurationSource(is, url);
-    }
-
-    /**
-     * Default Factory.
-     */
-    private static class Factory extends ConfigurationFactory {
-
-        private static final String ALL_TYPES = "*";
-
-        /**
-         * Default Factory Constructor.
-         * @param name The configuration name.
-         * @param configLocation The configuration location.
-         * @return The Configuration.
-         */
-        @Override
-        public Configuration getConfiguration(final String name, final URI configLocation) {
-
-            if (configLocation == null) {
-                final String configLocationStr = this.substitutor.replace(PropertiesUtil.getProperties()
-                        .getStringProperty(CONFIGURATION_FILE_PROPERTY));
-                if (configLocationStr != null) {
-                    final String[] sources = configLocationStr.split(",");
-                    if (sources.length > 1) {
-                        final List<AbstractConfiguration> configs = new ArrayList<>();
-                        for (final String sourceLocation : sources) {
-                            final Configuration config = getConfiguration(sourceLocation.trim());
-                            if (config != null && config instanceof AbstractConfiguration) {
-                                configs.add((AbstractConfiguration) config);
-                            } else {
-                                LOGGER.error("Failed to created configuration at {}", sourceLocation);
-                                return null;
-                            }
-                        }
-                        return new CompositeConfiguration(configs);
-                    }
-                    return getConfiguration(configLocationStr);
-                }
-                for (final ConfigurationFactory factory : getFactories()) {
-                    final String[] types = factory.getSupportedTypes();
-                    if (types != null) {
-                        for (final String type : types) {
-                            if (type.equals(ALL_TYPES)) {
-                                final Configuration config = factory.getConfiguration(name, configLocation);
-                                if (config != null) {
-                                    return config;
-                                }
-                            }
-                        }
-                    }
-                }
-            } else {
-                // configLocation != null
-                final String configLocationStr = configLocation.toString();
-                for (final ConfigurationFactory factory : getFactories()) {
-                    final String[] types = factory.getSupportedTypes();
-                    if (types != null) {
-                        for (final String type : types) {
-                            if (type.equals(ALL_TYPES) || configLocationStr.endsWith(type)) {
-                                final Configuration config = factory.getConfiguration(name, configLocation);
-                                if (config != null) {
-                                    return config;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-
-            Configuration config = getConfiguration(true, name);
-            if (config == null) {
-                config = getConfiguration(true, null);
-                if (config == null) {
-                    config = getConfiguration(false, name);
-                    if (config == null) {
-                        config = getConfiguration(false, null);
-                    }
-                }
-            }
-            if (config != null) {
-                return config;
-            }
-            LOGGER.error("No log4j2 configuration file found. Using default configuration: logging only errors to the console.");
-            return new DefaultConfiguration();
-        }
-
-        private Configuration getConfiguration(final String configLocationStr) {
-            ConfigurationSource source = null;
-            try {
-                source = getInputFromUri(NetUtils.toURI(configLocationStr));
-            } catch (final Exception ex) {
-                // Ignore the error and try as a String.
-                LOGGER.catching(Level.DEBUG, ex);
-            }
-            if (source == null) {
-                final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
-                source = getInputFromString(configLocationStr, loader);
-            }
-            if (source != null) {
-                for (final ConfigurationFactory factory : getFactories()) {
-                    final String[] types = factory.getSupportedTypes();
-                    if (types != null) {
-                        for (final String type : types) {
-                            if (type.equals(ALL_TYPES) || configLocationStr.endsWith(type)) {
-                                final Configuration config = factory.getConfiguration(source);
-                                if (config != null) {
-                                    return config;
-                                }
-                            }
-                        }
-                    }
-                }
-            }
-            return null;
-        }
-
-        private Configuration getConfiguration(final boolean isTest, final String name) {
-            final boolean named = Strings.isNotEmpty(name);
-            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
-            for (final ConfigurationFactory factory : getFactories()) {
-                String configName;
-                final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX;
-                final String [] types = factory.getSupportedTypes();
-                if (types == null) {
-                    continue;
-                }
-
-                for (final String suffix : types) {
-                    if (suffix.equals(ALL_TYPES)) {
-                        continue;
-                    }
-                    configName = named ? prefix + name + suffix : prefix + suffix;
-
-                    final ConfigurationSource source = getInputFromResource(configName, loader);
-                    if (source != null) {
-                        return factory.getConfiguration(source);
-                    }
-                }
-            }
-            return null;
-        }
-
-        @Override
-        public String[] getSupportedTypes() {
-            return null;
-        }
-
-        @Override
-        public Configuration getConfiguration(final ConfigurationSource source) {
-            if (source != null) {
-                final String config = source.getLocation();
-                for (final ConfigurationFactory factory : getFactories()) {
-                    final String[] types = factory.getSupportedTypes();
-                    if (types != null) {
-                        for (final String type : types) {
-                            if (type.equals(ALL_TYPES) || config != null && config.endsWith(type)) {
-                                final Configuration c = factory.getConfiguration(source);
-                                if (c != null) {
-                                    LOGGER.debug("Loaded configuration from {}", source);
-                                    return c;
-                                }
-                                LOGGER.error("Cannot determine the ConfigurationFactory to use for {}", config);
-                                return null;
-                            }
-                        }
-                    }
-                }
-            }
-            LOGGER.error("Cannot process configuration, input source is null");
-            return null;
-        }
-    }
-
-    static List<ConfigurationFactory> getFactories() {
-        return factories;
-    }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.config;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
+import org.apache.logging.log4j.core.config.composite.CompositeConfiguration;
+import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
+import org.apache.logging.log4j.core.config.plugins.util.PluginType;
+import org.apache.logging.log4j.core.lookup.Interpolator;
+import org.apache.logging.log4j.core.lookup.StrSubstitutor;
+import org.apache.logging.log4j.core.util.FileUtils;
+import org.apache.logging.log4j.core.util.Loader;
+import org.apache.logging.log4j.core.util.NetUtils;
+import org.apache.logging.log4j.core.util.ReflectionUtil;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.logging.log4j.util.LoaderUtil;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.apache.logging.log4j.util.Strings;
+
+/**
+ * Factory class for parsed {@link Configuration} objects from a configuration file.
+ * ConfigurationFactory allows the configuration implementation to be
+ * dynamically chosen in 1 of 3 ways:
+ * <ol>
+ * <li>A system property named "log4j.configurationFactory" can be set with the
+ * name of the ConfigurationFactory to be used.</li>
+ * <li>
+ * {@linkplain #setConfigurationFactory(ConfigurationFactory)} can be called
+ * with the instance of the ConfigurationFactory to be used. This must be called
+ * before any other calls to Log4j.</li>
+ * <li>
+ * A ConfigurationFactory implementation can be added to the classpath and configured as a plugin in the
+ * {@link #CATEGORY ConfigurationFactory} category. The {@link Order} annotation should be used to configure the
+ * factory to be the first one inspected. See
+ * {@linkplain org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory} for an example.</li>
+ * </ol>
+ *
+ * If the ConfigurationFactory that was added returns null on a call to
+ * getConfiguration then any other ConfigurationFactories found as plugins will
+ * be called in their respective order. DefaultConfiguration is always called
+ * last if no configuration has been returned.
+ */
+public abstract class ConfigurationFactory extends ConfigurationBuilderFactory {
+    
+    public ConfigurationFactory() {
+        super();
+        // TEMP For breakpoints
+    }
+
+    /**
+     * Allows the ConfigurationFactory class to be specified as a system property.
+     */
+    public static final String CONFIGURATION_FACTORY_PROPERTY = "log4j.configurationFactory";
+
+    /**
+     * Allows the location of the configuration file to be specified as a system property.
+     */
+    public static final String CONFIGURATION_FILE_PROPERTY = "log4j.configurationFile";
+
+    /**
+     * Plugin category used to inject a ConfigurationFactory {@link org.apache.logging.log4j.core.config.plugins.Plugin}
+     * class.
+     *
+     * @since 2.1
+     */
+    public static final String CATEGORY = "ConfigurationFactory";
+
+    /**
+     * Allows subclasses access to the status logger without creating another instance.
+     */
+    protected static final Logger LOGGER = StatusLogger.getLogger();
+
+    /**
+     * File name prefix for test configurations.
+     */
+    protected static final String TEST_PREFIX = "log4j2-test";
+
+    /**
+     * File name prefix for standard configurations.
+     */
+    protected static final String DEFAULT_PREFIX = "log4j2";
+
+    /**
+     * The name of the classloader URI scheme.
+     */
+    private static final String CLASS_LOADER_SCHEME = "classloader";
+
+    /**
+     * The name of the classpath URI scheme, synonymous with the classloader URI scheme.
+     */
+    private static final String CLASS_PATH_SCHEME = "classpath";
+
+    private static volatile List<ConfigurationFactory> factories = null;
+
+    private static ConfigurationFactory configFactory = new Factory();
+
+    protected final StrSubstitutor substitutor = new StrSubstitutor(new Interpolator());
+
+    private static final Lock LOCK = new ReentrantLock();
+
+    /**
+     * Returns the ConfigurationFactory.
+     * @return the ConfigurationFactory.
+     */
+    public static ConfigurationFactory getInstance() {
+        // volatile works in Java 1.6+, so double-checked locking also works properly
+        //noinspection DoubleCheckedLocking
+        if (factories == null) {
+            LOCK.lock();
+            try {
+                if (factories == null) {
+                    final List<ConfigurationFactory> list = new ArrayList<>();
+                    final String factoryClass = PropertiesUtil.getProperties().getStringProperty(CONFIGURATION_FACTORY_PROPERTY);
+                    if (factoryClass != null) {
+                        addFactory(list, factoryClass);
+                    }
+                    final PluginManager manager = new PluginManager(CATEGORY);
+                    manager.collectPlugins();
+                    final Map<String, PluginType<?>> plugins = manager.getPlugins();
+                    final List<Class<? extends ConfigurationFactory>> ordered = new ArrayList<>(plugins.size());
+                    for (final PluginType<?> type : plugins.values()) {
+                        try {
+                            ordered.add(type.getPluginClass().asSubclass(ConfigurationFactory.class));
+                        } catch (final Exception ex) {
+                            LOGGER.warn("Unable to add class {}", type.getPluginClass(), ex);
+                        }
+                    }
+                    Collections.sort(ordered, OrderComparator.getInstance());
+                    for (final Class<? extends ConfigurationFactory> clazz : ordered) {
+                        addFactory(list, clazz);
+                    }
+                    // see above comments about double-checked locking
+                    //noinspection NonThreadSafeLazyInitialization
+                    factories = Collections.unmodifiableList(list);
+                }
+            } finally {
+                LOCK.unlock();
+            }
+        }
+
+        LOGGER.debug("Using configurationFactory {}", configFactory);
+        return configFactory;
+    }
+
+    private static void addFactory(final Collection<ConfigurationFactory> list, final String factoryClass) {
+        try {
+            addFactory(list, LoaderUtil.loadClass(factoryClass).asSubclass(ConfigurationFactory.class));
+        } catch (final Exception ex) {
+            LOGGER.error("Unable to load class {}", factoryClass, ex);
+        }
+    }
+
+    private static void addFactory(final Collection<ConfigurationFactory> list,
+                                   final Class<? extends ConfigurationFactory> factoryClass) {
+        try {
+            list.add(ReflectionUtil.instantiate(factoryClass));
+        } catch (final Exception ex) {
+            LOGGER.error("Unable to create instance of {}", factoryClass.getName(), ex);
+        }
+    }
+
+    /**
+     * Sets the configuration factory. This method is not intended for general use and may not be thread safe.
+     * @param factory the ConfigurationFactory.
+     */
+    public static void setConfigurationFactory(final ConfigurationFactory factory) {
+        configFactory = factory;
+    }
+
+    /**
+     * Resets the ConfigurationFactory to the default. This method is not intended for general use and may
+     * not be thread safe.
+     */
+    public static void resetConfigurationFactory() {
+        configFactory = new Factory();
+    }
+
+    /**
+     * Removes the ConfigurationFactory. This method is not intended for general use and may not be thread safe.
+     * @param factory The factory to remove.
+     */
+    public static void removeConfigurationFactory(final ConfigurationFactory factory) {
+        if (configFactory == factory) {
+            configFactory = new Factory();
+        }
+    }
+
+    protected abstract String[] getSupportedTypes();
+
+    protected boolean isActive() {
+        return true;
+    }
+
+    public abstract Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source);
+
+    /**
+     * Returns the Configuration.
+     * @param loggerContext The logger context
+     * @param name The configuration name.
+     * @param configLocation The configuration location.
+     * @return The Configuration.
+     */
+    public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) {
+        if (!isActive()) {
+            return null;
+        }
+        if (configLocation != null) {
+            final ConfigurationSource source = getInputFromUri(configLocation);
+            if (source != null) {
+                return getConfiguration(loggerContext, source);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Returns the Configuration obtained using a given ClassLoader.
+     * @param loggerContext TODO
+     * @param name The configuration name.
+     * @param configLocation A URI representing the location of the configuration.
+     * @param loader The default ClassLoader to use. If this is {@code null}, then the
+     *               {@linkplain LoaderUtil#getThreadContextClassLoader() default ClassLoader} will be used.
+     *
+     * @return The Configuration.
+     */
+    public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation, final ClassLoader loader) {
+        if (!isActive()) {
+            return null;
+        }
+        if (loader == null) {
+            return getConfiguration(loggerContext, name, configLocation);
+        }
+        if (isClassLoaderUri(configLocation)) {
+            final String path = extractClassLoaderUriPath(configLocation);
+            final ConfigurationSource source = getInputFromResource(path, loader);
+            if (source != null) {
+                final Configuration configuration = getConfiguration(loggerContext, source);
+                if (configuration != null) {
+                    return configuration;
+                }
+            }
+        }
+        return getConfiguration(loggerContext, name, configLocation);
+    }
+
+    /**
+     * Loads the configuration from a URI.
+     * @param configLocation A URI representing the location of the configuration.
+     * @return The ConfigurationSource for the configuration.
+     */
+    protected ConfigurationSource getInputFromUri(final URI configLocation) {
+        final File configFile = FileUtils.fileFromUri(configLocation);
+        if (configFile != null && configFile.exists() && configFile.canRead()) {
+            try {
+                return new ConfigurationSource(new FileInputStream(configFile), configFile);
+            } catch (final FileNotFoundException ex) {
+                LOGGER.error("Cannot locate file {}", configLocation.getPath(), ex);
+            }
+        }
+        if (isClassLoaderUri(configLocation)) {
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
+            final String path = extractClassLoaderUriPath(configLocation);
+            final ConfigurationSource source = getInputFromResource(path, loader);
+            if (source != null) {
+                return source;
+            }
+        }
+        if (!configLocation.isAbsolute()) { // LOG4J2-704 avoid confusing error message thrown by uri.toURL()
+            LOGGER.error("File not found in file system or classpath: {}", configLocation.toString());
+            return null;
+        }
+        try {
+            return new ConfigurationSource(configLocation.toURL().openStream(), configLocation.toURL());
+        } catch (final MalformedURLException ex) {
+            LOGGER.error("Invalid URL {}", configLocation.toString(), ex);
+        } catch (final Exception ex) {
+            LOGGER.error("Unable to access {}", configLocation.toString(), ex);
+        }
+        return null;
+    }
+
+    private static boolean isClassLoaderUri(final URI uri) {
+        if (uri == null) {
+            return false;
+        }
+        final String scheme = uri.getScheme();
+        return scheme == null || scheme.equals(CLASS_LOADER_SCHEME) || scheme.equals(CLASS_PATH_SCHEME);
+    }
+
+    private static String extractClassLoaderUriPath(final URI uri) {
+        return uri.getScheme() == null ? uri.getPath() : uri.getSchemeSpecificPart();
+    }
+
+    /**
+     * Loads the configuration from the location represented by the String.
+     * @param config The configuration location.
+     * @param loader The default ClassLoader to use.
+     * @return The InputSource to use to read the configuration.
+     */
+    protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) {
+        try {
+            final URL url = new URL(config);
+            return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI()));
+        } catch (final Exception ex) {
+            final ConfigurationSource source = getInputFromResource(config, loader);
+            if (source == null) {
+                try {
+                    final File file = new File(config);
+                    return new ConfigurationSource(new FileInputStream(file), file);
+                } catch (final FileNotFoundException fnfe) {
+                    // Ignore the exception
+                    LOGGER.catching(Level.DEBUG, fnfe);
+                }
+            }
+            return source;
+        }
+    }
+
+    /**
+     * Retrieves the configuration via the ClassLoader.
+     * @param resource The resource to load.
+     * @param loader The default ClassLoader to use.
+     * @return The ConfigurationSource for the configuration.
+     */
+    protected ConfigurationSource getInputFromResource(final String resource, final ClassLoader loader) {
+        final URL url = Loader.getResource(resource, loader);
+        if (url == null) {
+            return null;
+        }
+        InputStream is = null;
+        try {
+            is = url.openStream();
+        } catch (final IOException ioe) {
+            LOGGER.catching(Level.DEBUG, ioe);
+            return null;
+        }
+        if (is == null) {
+            return null;
+        }
+
+        if (FileUtils.isFile(url)) {
+            try {
+                return new ConfigurationSource(is, FileUtils.fileFromUri(url.toURI()));
+            } catch (final URISyntaxException ex) {
+                // Just ignore the exception.
+                LOGGER.catching(Level.DEBUG, ex);
+            }
+        }
+        return new ConfigurationSource(is, url);
+    }
+
+    /**
+     * Default Factory.
+     */
+    private static class Factory extends ConfigurationFactory {
+
+        private static final String ALL_TYPES = "*";
+
+        /**
+         * Default Factory Constructor.
+         * @param name The configuration name.
+         * @param configLocation The configuration location.
+         * @return The Configuration.
+         */
+        @Override
+        public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) {
+
+            if (configLocation == null) {
+                final String configLocationStr = this.substitutor.replace(PropertiesUtil.getProperties()
+                        .getStringProperty(CONFIGURATION_FILE_PROPERTY));
+                if (configLocationStr != null) {
+                    final String[] sources = configLocationStr.split(",");
+                    if (sources.length > 1) {
+                        final List<AbstractConfiguration> configs = new ArrayList<>();
+                        for (final String sourceLocation : sources) {
+                            final Configuration config = getConfiguration(loggerContext, sourceLocation.trim());
+                            if (config != null && config instanceof AbstractConfiguration) {
+                                configs.add((AbstractConfiguration) config);
+                            } else {
+                                LOGGER.error("Failed to created configuration at {}", sourceLocation);
+                                return null;
+                            }
+                        }
+                        return new CompositeConfiguration(configs);
+                    }
+                    return getConfiguration(loggerContext, configLocationStr);
+                }
+                for (final ConfigurationFactory factory : getFactories()) {
+                    final String[] types = factory.getSupportedTypes();
+                    if (types != null) {
+                        for (final String type : types) {
+                            if (type.equals(ALL_TYPES)) {
+                                final Configuration config = factory.getConfiguration(loggerContext, name, configLocation);
+                                if (config != null) {
+                                    return config;
+                                }
+                            }
+                        }
+                    }
+                }
+            } else {
+                // configLocation != null
+                final String configLocationStr = configLocation.toString();
+                for (final ConfigurationFactory factory : getFactories()) {
+                    final String[] types = factory.getSupportedTypes();
+                    if (types != null) {
+                        for (final String type : types) {
+                            if (type.equals(ALL_TYPES) || configLocationStr.endsWith(type)) {
+                                final Configuration config = factory.getConfiguration(loggerContext, name, configLocation);
+                                if (config != null) {
+                                    return config;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+
+            Configuration config = getConfiguration(loggerContext, true, name);
+            if (config == null) {
+                config = getConfiguration(loggerContext, true, null);
+                if (config == null) {
+                    config = getConfiguration(loggerContext, false, name);
+                    if (config == null) {
+                        config = getConfiguration(loggerContext, false, null);
+                    }
+                }
+            }
+            if (config != null) {
+                return config;
+            }
+            LOGGER.error("No log4j2 configuration file found. Using default configuration: logging only errors to the console.");
+            return new DefaultConfiguration();
+        }
+
+        private Configuration getConfiguration(final LoggerContext loggerContext, final String configLocationStr) {
+            ConfigurationSource source = null;
+            try {
+                source = getInputFromUri(NetUtils.toURI(configLocationStr));
+            } catch (final Exception ex) {
+                // Ignore the error and try as a String.
+                LOGGER.catching(Level.DEBUG, ex);
+            }
+            if (source == null) {
+                final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
+                source = getInputFromString(configLocationStr, loader);
+            }
+            if (source != null) {
+                for (final ConfigurationFactory factory : getFactories()) {
+                    final String[] types = factory.getSupportedTypes();
+                    if (types != null) {
+                        for (final String type : types) {
+                            if (type.equals(ALL_TYPES) || configLocationStr.endsWith(type)) {
+                                final Configuration config = factory.getConfiguration(loggerContext, source);
+                                if (config != null) {
+                                    return config;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            return null;
+        }
+
+        private Configuration getConfiguration(final LoggerContext loggerContext, final boolean isTest, final String name) {
+            final boolean named = Strings.isNotEmpty(name);
+            final ClassLoader loader = LoaderUtil.getThreadContextClassLoader();
+            for (final ConfigurationFactory factory : getFactories()) {
+                String configName;
+                final String prefix = isTest ? TEST_PREFIX : DEFAULT_PREFIX;
+                final String [] types = factory.getSupportedTypes();
+                if (types == null) {
+                    continue;
+                }
+
+                for (final String suffix : types) {
+                    if (suffix.equals(ALL_TYPES)) {
+                        continue;
+                    }
+                    configName = named ? prefix + name + suffix : prefix + suffix;
+
+                    final ConfigurationSource source = getInputFromResource(configName, loader);
+                    if (source != null) {
+                        return factory.getConfiguration(loggerContext, source);
+                    }
+                }
+            }
+            return null;
+        }
+
+        @Override
+        public String[] getSupportedTypes() {
+            return null;
+        }
+
+        @Override
+        public Configuration getConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
+            if (source != null) {
+                final String config = source.getLocation();
+                for (final ConfigurationFactory factory : getFactories()) {
+                    final String[] types = factory.getSupportedTypes();
+                    if (types != null) {
+                        for (final String type : types) {
+                            if (type.equals(ALL_TYPES) || config != null && config.endsWith(type)) {
+                                final Configuration c = factory.getConfiguration(loggerContext, source);
+                                if (c != null) {
+                                    LOGGER.debug("Loaded configuration from {}", source);
+                                    return c;
+                                }
+                                LOGGER.error("Cannot determine the ConfigurationFactory to use for {}", config);
+                                return null;
+                            }
+                        }
+                    }
+                }
+            }
+            LOGGER.error("Cannot process configuration, input source is null");
+            return null;
+        }
+    }
+
+    static List<ConfigurationFactory> getFactories() {
+        return factories;
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
index e186c44..cbedf7c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/DefaultConfiguration.java
@@ -43,7 +43,7 @@ public class DefaultConfiguration extends AbstractConfiguration {
      * Constructor to create the default configuration.
      */
     public DefaultConfiguration() {
-        super(ConfigurationSource.NULL_SOURCE);
+        super(null, ConfigurationSource.NULL_SOURCE);
         setToDefault();
     }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
index 9b04b50..db6f779 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/NullConfiguration.java
@@ -29,7 +29,7 @@ public class NullConfiguration extends AbstractConfiguration {
     public static final String NULL_NAME = "Null";
 
     public NullConfiguration() {
-        super(ConfigurationSource.NULL_SOURCE);
+        super(null, ConfigurationSource.NULL_SOURCE);
 
         setName(NULL_NAME);
         final LoggerConfig root = getRootLogger();

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java
index 1fbfa01..0cc9ae8 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/api/ConfigurationBuilder.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.config.builder.api;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.util.Builder;
@@ -391,6 +392,12 @@ public interface ConfigurationBuilder<T extends Configuration> extends Builder<T
     ConfigurationBuilder<T> setDestination(String destination);
 
     /**
+     * Sets the logger context.
+     * @param loggerContext the logger context.
+     */
+    void setLoggerContext(LoggerContext loggerContext);
+
+    /**
      * Add the properties for the root node.
      * @param key The property key.
      * @param value The property value.
@@ -405,4 +412,5 @@ public interface ConfigurationBuilder<T extends Configuration> extends Builder<T
      * @return The constructed Configuration.
      */
     T build(boolean initialize);
+
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
index 029caf2..ca35d12 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/BuiltConfiguration.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
 import java.util.Arrays;
 import java.util.List;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.AbstractConfiguration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.ConfiguratonFileWatcher;
@@ -53,8 +54,8 @@ public class BuiltConfiguration extends AbstractConfiguration {
     private Component scriptsComponent;
     private String contentType = "text";
 
-    public BuiltConfiguration(final ConfigurationSource source, final Component rootComponent) {
-        super(source);
+    public BuiltConfiguration(LoggerContext loggerContext, final ConfigurationSource source, final Component rootComponent) {
+        super(loggerContext, source);
         statusConfig = new StatusConfiguration().withVerboseClasses(VERBOSE_CLASSES).withStatus(getDefaultStatus());
         for (final Component component : rootComponent.getComponents()) {
             switch (component.getPluginType()) {

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
index b455100..000da5d 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/builder/impl/DefaultConfigurationBuilder.java
@@ -21,6 +21,7 @@ import java.util.List;
 
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -53,15 +54,15 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
     private Component scripts;
     private final Class<T> clazz;
     private ConfigurationSource source;
-    private int monitorInterval = 0;
-    private Level level = null;
-    private String verbosity = null;
-    private String destination = null;
-    private String packages = null;
-    private String shutdownFlag = null;
-    private String advertiser = null;
-
-    private String name = null;
+    private int monitorInterval;
+    private Level level;
+    private String verbosity;
+    private String destination;
+    private String packages;
+    private String shutdownFlag;
+    private String advertiser;
+    private LoggerContext loggerContext;
+    private String name;
 
     @SuppressWarnings("unchecked")
     public DefaultConfigurationBuilder() {
@@ -152,8 +153,8 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
             if (source == null) {
                 source = ConfigurationSource.NULL_SOURCE;
             }
-            final Constructor<T> constructor = clazz.getConstructor(ConfigurationSource.class, Component.class);
-            configuration = constructor.newInstance(source, root);
+            final Constructor<T> constructor = clazz.getConstructor(LoggerContext.class, ConfigurationSource.class, Component.class);
+            configuration = constructor.newInstance(loggerContext, source, root);
             configuration.setMonitorInterval(monitorInterval);
             configuration.getRootNode().getAttributes().putAll(root.getAttributes());
             if (name != null) {
@@ -400,8 +401,14 @@ public class DefaultConfigurationBuilder<T extends BuiltConfiguration> implement
     }
 
     @Override
+    public void setLoggerContext(LoggerContext loggerContext) {
+        this.loggerContext = loggerContext;
+    }
+
+    @Override
     public ConfigurationBuilder<T> addRootProperty(final String key, final String value) {
         root.getAttributes().put(key, value);
         return this;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
index f272fc1..a1f1557 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/composite/CompositeConfiguration.java
@@ -62,7 +62,7 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
      * @param configurations The List of Configurations to merge.
      */
     public CompositeConfiguration(final List<? extends AbstractConfiguration> configurations) {
-        super(ConfigurationSource.NULL_SOURCE);
+        super(null, ConfigurationSource.NULL_SOURCE);
         rootNode = configurations.get(0).getRootNode();
         this.configurations = configurations;
         final String mergeStrategyClassName = PropertiesUtil.getProperties().getStringProperty(MERGE_STRATEGY_PROPERTY,
@@ -152,7 +152,7 @@ public class CompositeConfiguration extends AbstractConfiguration implements Rec
             if (sourceURI != null) {
                 LOGGER.warn("Unable to determine URI for configuration {}, changes to it will be ignored",
                         config.getName());
-                currentConfig = factory.getConfiguration(config.getName(), sourceURI);
+                currentConfig = factory.getConfiguration(getLoggerContext(), config.getName(), sourceURI);
                 if (currentConfig == null) {
                     LOGGER.warn("Unable to reload configuration {}, changes to it will be ignored", config.getName());
                     currentConfig = config;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
index 427fa6d..0d87268 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfiguration.java
@@ -26,9 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.AbstractConfiguration;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -42,6 +40,10 @@ import org.apache.logging.log4j.core.config.status.StatusConfiguration;
 import org.apache.logging.log4j.core.util.FileWatcher;
 import org.apache.logging.log4j.core.util.Patterns;
 
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
 /**
  * Creates a Node hierarchy from a JSON file.
  */
@@ -51,8 +53,8 @@ public class JsonConfiguration extends AbstractConfiguration implements Reconfig
     private final List<Status> status = new ArrayList<>();
     private JsonNode root;
 
-    public JsonConfiguration(final ConfigurationSource configSource) {
-        super(configSource);
+    public JsonConfiguration(final LoggerContext loggerContext, final ConfigurationSource configSource) {
+        super(loggerContext, configSource);
         final File configFile = configSource.getFile();
         byte[] buffer;
         try {
@@ -140,7 +142,7 @@ public class JsonConfiguration extends AbstractConfiguration implements Reconfig
             if (source == null) {
                 return null;
             }
-            return new JsonConfiguration(source);
+            return new JsonConfiguration(getLoggerContext(), source);
         } catch (final IOException ex) {
             LOGGER.error("Cannot locate file {}", getConfigurationSource(), ex);
         }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
index 7b45cf9..d802e0e 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/json/JsonConfigurationFactory.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.config.json;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -60,11 +61,11 @@ public class JsonConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
+    public Configuration getConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
         if (!isActive) {
             return null;
         }
-        return new JsonConfiguration(source);
+        return new JsonConfiguration(loggerContext, source);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
index a5eaae9..b89b30c 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.config.properties;
 
 import java.io.IOException;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.Reconfigurable;
@@ -30,8 +31,9 @@ import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
  */
 public class PropertiesConfiguration extends BuiltConfiguration implements Reconfigurable {
 
-    public PropertiesConfiguration(final ConfigurationSource source, final Component root) {
-        super(source, root);
+    // ctor is called through reflection.
+    public PropertiesConfiguration(LoggerContext loggerContext, final ConfigurationSource source, final Component root) {
+        super(loggerContext, source, root);
     }
 
     @Override
@@ -42,7 +44,7 @@ public class PropertiesConfiguration extends BuiltConfiguration implements Recon
                 return null;
             }
             final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
-            final PropertiesConfiguration config = factory.getConfiguration(source);
+            final PropertiesConfiguration config = factory.getConfiguration(getLoggerContext(), source);
             return config == null || config.getState() != State.INITIALIZING ? null : config;
         } catch (final IOException ex) {
             LOGGER.error("Cannot locate file {}: {}", getConfigurationSource(), ex);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
index d9245ad..9a676a0 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationBuilder.java
@@ -22,6 +22,7 @@ import java.util.Map;
 import java.util.Properties;
 
 import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.LoggerConfig;
@@ -61,6 +62,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
     private static final String CONFIG_TYPE = "type";
 
     private final ConfigurationBuilder<PropertiesConfiguration> builder;
+    private LoggerContext loggerContext;
     private Properties rootProperties;
 
     public PropertiesConfigurationBuilder() {
@@ -79,7 +81,6 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
 
     @Override
     public PropertiesConfiguration build() {
-        final Map<String, String> rootProps = new HashMap<>();
         for (final String key : rootProperties.stringPropertyNames()) {
             if (!key.contains(".")) {
                 builder.addRootProperty(key, rootProperties.getProperty(key));
@@ -179,7 +180,9 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
         if (props.size() > 0) {
             builder.add(createRootLogger(props));
         }
-
+        
+        builder.setLoggerContext(loggerContext);
+        
         return builder.build(false);
     }
 
@@ -366,4 +369,13 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
         }
         return loggerBuilder;
     }
+
+    public PropertiesConfigurationBuilder setLoggerContext(LoggerContext loggerContext) {
+        this.loggerContext = loggerContext;
+        return this;
+    }
+
+    public LoggerContext getLoggerContext() {
+        return loggerContext;
+    }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
index 1098e8f..2263267 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationFactory.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.ConfigurationException;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -41,14 +42,17 @@ public class PropertiesConfigurationFactory extends ConfigurationFactory {
     }
 
     @Override
-    public PropertiesConfiguration getConfiguration(final ConfigurationSource source) {
+    public PropertiesConfiguration getConfiguration(LoggerContext loggerContext, final ConfigurationSource source) {
         final Properties properties = new Properties();
         try (final InputStream configStream = source.getInputStream()) {
             properties.load(configStream);
         } catch (final IOException ioe) {
             throw new ConfigurationException("Unable to load " + source.toString(), ioe);
         }
-        return new PropertiesConfigurationBuilder().setConfigurationSource(source)
-                .setRootProperties(properties).build();
+        return new PropertiesConfigurationBuilder()
+                .setConfigurationSource(source)
+                .setRootProperties(properties)
+                .setLoggerContext(loggerContext)
+                .build();
     }
 }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
index 799a49e..2608552 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfiguration.java
@@ -35,6 +35,7 @@ import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.Validator;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.AbstractConfiguration;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -75,8 +76,8 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
     private boolean strict;
     private String schemaResource;
 
-    public XmlConfiguration(final ConfigurationSource configSource) {
-        super(configSource);
+    public XmlConfiguration(final LoggerContext loggerContext, final ConfigurationSource configSource) {
+        super(loggerContext, configSource);
         final File configFile = configSource.getFile();
         byte[] buffer = null;
 
@@ -255,7 +256,7 @@ public class XmlConfiguration extends AbstractConfiguration implements Reconfigu
             if (source == null) {
                 return null;
             }
-            final XmlConfiguration config = new XmlConfiguration(source);
+            final XmlConfiguration config = new XmlConfiguration(getLoggerContext(), source);
             return config.rootElement == null ? null : config;
         } catch (final IOException ex) {
             LOGGER.error("Cannot locate file {}", getConfigurationSource(), ex);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
index 1c3e919..9de84aa 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/xml/XmlConfigurationFactory.java
@@ -16,6 +16,7 @@
  */
 package org.apache.logging.log4j.core.config.xml;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationFactory;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
@@ -40,8 +41,8 @@ public class XmlConfigurationFactory extends ConfigurationFactory {
      * @return The Configuration.
      */
     @Override
-    public Configuration getConfiguration(final ConfigurationSource source) {
-        return new XmlConfiguration(source);
+    public Configuration getConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
+        return new XmlConfiguration(loggerContext, source);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/85c5e81a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
index 6350a48..ed7e9ba 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/yaml/YamlConfiguration.java
@@ -18,6 +18,7 @@ package org.apache.logging.log4j.core.config.yaml;
 
 import java.io.IOException;
 
+import org.apache.logging.log4j.core.LoggerContext;
 import org.apache.logging.log4j.core.config.Configuration;
 import org.apache.logging.log4j.core.config.ConfigurationSource;
 import org.apache.logging.log4j.core.config.json.JsonConfiguration;
@@ -28,8 +29,8 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
 
 public class YamlConfiguration extends JsonConfiguration {
 
-    public YamlConfiguration(final ConfigurationSource configSource) {
-        super(configSource);
+    public YamlConfiguration(final LoggerContext loggerContext, final ConfigurationSource configSource) {
+        super(loggerContext, configSource);
     }
 
     @Override
@@ -44,7 +45,7 @@ public class YamlConfiguration extends JsonConfiguration {
             if (source == null) {
                 return null;
             }
-            return new YamlConfiguration(source);
+            return new YamlConfiguration(getLoggerContext(), source);
         } catch (final IOException ex) {
             LOGGER.error("Cannot locate file {}", getConfigurationSource(), ex);
         }


[08/18] logging-log4j2 git commit: [LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not supported. Update changes.xml.

Posted by gg...@apache.org.
[LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not
supported. Update changes.xml.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/73323cd9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/73323cd9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/73323cd9

Branch: refs/heads/LOG4J2-1539
Commit: 73323cd968f2c63a1b75ae3b5d4122a495945e70
Parents: 2d5812b
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:07:16 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:07:16 2016 -0700

----------------------------------------------------------------------
 src/changes/changes.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/73323cd9/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index dbc3310..c6e62dd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -33,7 +33,7 @@
       <action issue="LOG4J2-1490" dev="ggregory" type="fix" due-to="Krzysztof Taborski, Gary Gregory">
         Log4j2 is creating empty log files.
       </action>
-      <action issue="LOG4J2-1320" dev="ggregory" type="fix" due-to="Paresh Varke, Pierrick Hymbert">
+      <action issue="LOG4J2-1320" dev="ggregory" type="fix" due-to="Paresh Varke, Pierrick Hymbert, Gary Gregory">
         Custom plugins are not loaded, URL protocol vfs is not supported.
       </action>
       <action issue="LOG4J2-1541" dev="ggregory" type="fix" due-to="Gary Gregory">


[10/18] logging-log4j2 git commit: [LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not supported. Tweaks.

Posted by gg...@apache.org.
[LOG4J2-1320] Custom plugins are not loaded, URL protocol vfs is not
supported. Tweaks.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e0330275
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e0330275
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e0330275

Branch: refs/heads/LOG4J2-1539
Commit: e0330275af40bd7e36b085ff03e108e9c5ed886c
Parents: 4157ef8
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:16:52 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:16:52 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/config/plugins/util/ResolverUtilTest.java  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e0330275/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
index 76ab740..92e6ee9 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
@@ -182,18 +182,18 @@ public class ResolverUtilTest {
     static File compile(String suffix) throws IOException {
         final File orig = new File("target/test-classes/customplugin/FixedStringLayout.java.source");
         final File workDir = new File("target/resolverutil" + suffix);
-        final File javaFile = new File(workDir, "customplugin" + suffix + "/FixedString" + suffix + "Layout.java");
-        final File parent = javaFile.getParentFile();
+        final File f = new File(workDir, "customplugin" + suffix + "/FixedString" + suffix + "Layout.java");
+        final File parent = f.getParentFile();
         if (!parent.exists()) {
-          assertTrue("Create customplugin" + suffix + " folder KO", javaFile.getParentFile().mkdirs());
+          assertTrue("Create customplugin" + suffix + " folder KO", f.getParentFile().mkdirs());
         }
   
         String content = new String(Files.readAllBytes(orig.toPath()))
           .replaceAll("FixedString", "FixedString" + suffix)
           .replaceAll("customplugin", "customplugin" + suffix);
-        Files.write(javaFile.toPath(), content.getBytes());
+        Files.write(f.toPath(), content.getBytes());
   
-        PluginManagerPackagesTest.compile(javaFile);
+        PluginManagerPackagesTest.compile(f);
         return workDir;
     }
 


[04/18] logging-log4j2 git commit: [LOG4J2-1506] Unregister JMX ignores log4j2.disable.jmx property.

Posted by gg...@apache.org.
[LOG4J2-1506] Unregister JMX ignores log4j2.disable.jmx property.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8b40c1f0
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8b40c1f0
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8b40c1f0

Branch: refs/heads/LOG4J2-1539
Commit: 8b40c1f0e3b53277c399511923f9d7b2aa110fea
Parents: 30ea283
Author: Gary Gregory <gg...@apache.org>
Authored: Wed Aug 24 08:05:52 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed Aug 24 08:05:52 2016 -0700

----------------------------------------------------------------------
 .../src/main/java/org/apache/logging/log4j/core/jmx/Server.java  | 4 ++++
 1 file changed, 4 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8b40c1f0/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
index 39cafeb..438f501 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
@@ -238,6 +238,10 @@ public final class Server {
      * @param loggerContextName name of the logger context to unregister
      */
     public static void unregisterLoggerContext(final String loggerContextName) {
+        if (isJmxDisabled()) {
+            LOGGER.debug("JMX disabled for Log4j2. Not unregistering MBeans.");
+            return;
+        }
         final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         unregisterLoggerContext(loggerContextName, mbs);
     }


[06/18] logging-log4j2 git commit: Code clean-up

Posted by gg...@apache.org.
Code clean-up


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/fadd676e
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/fadd676e
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/fadd676e

Branch: refs/heads/LOG4J2-1539
Commit: fadd676ea2b149fdf725a028646cf1247398bdcf
Parents: 33aaf3d
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Thu Aug 25 21:30:21 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Thu Aug 25 21:40:09 2016 +0200

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java | 172 +++++++++----------
 1 file changed, 80 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/fadd676e/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
----------------------------------------------------------------------
diff --git a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
index f98f909..11f7f76 100644
--- a/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
+++ b/log4j-1.2-api/src/main/java/org/apache/log4j/config/Log4j1ConfigurationParser.java
@@ -50,9 +50,14 @@ import java.util.Properties;
  * <li>layout</li>
  * </ul>
  * </ul>
+ *
+ * This class is not thread-safe.
  */
 public class Log4j1ConfigurationParser {
 
+    private final Properties properties = new Properties();
+    private final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
+
     /**
      * Parse a Log4j 1.2 properties configuration file into a ConfigurationBuilder.
      *
@@ -60,48 +65,39 @@ public class Log4j1ConfigurationParser {
      * @return  the populated ConfigurationBuilder
      * @throws IOException  if unable to read the input
      */
-    public ConfigurationBuilder<BuiltConfiguration> buildConfigurationBuilder(InputStream input) throws IOException {
-        final ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
-        builder.setConfigurationName("Log4j1");
-        final Properties properties = new Properties();
+    public ConfigurationBuilder<BuiltConfiguration> buildConfigurationBuilder(final InputStream input) throws IOException {
         properties.load(input);
-        final String rootCategoryValue = getRootCategoryValue(properties);
-        final String rootLoggerValue = getRootLoggerValue(properties);
+        final String rootCategoryValue = getLog4jValue("rootCategory");
+        final String rootLoggerValue = getLog4jValue("rootLogger");
         if (rootCategoryValue == null && rootLoggerValue == null) {
             // This is not a Log4j 1 properties configuration file.
             return null;
         }
+        builder.setConfigurationName("Log4j1");
         // DEBUG
-        final String debugValue = getLog4jValue(properties, "debug");
+        final String debugValue = getLog4jValue("debug");
         if (Boolean.valueOf(debugValue)) {
             builder.setStatusLevel(Level.DEBUG);
         }
         // Root
-        final String[] sortedAppenderNamesC = buildRootLogger(builder, getRootCategoryValue(properties));
-        final String[] sortedAppenderNamesL = buildRootLogger(builder, getRootLoggerValue(properties));
+        final String[] sortedAppenderNamesC = buildRootLogger(getLog4jValue("rootCategory"));
+        final String[] sortedAppenderNamesL = buildRootLogger(getLog4jValue("rootLogger"));
         final String[] sortedAppenderNames = sortedAppenderNamesL.length > 0 ? sortedAppenderNamesL
                 : sortedAppenderNamesC;
         // Appenders
-        final Map<String, String> classNameToProperty = buildClassToPropertyPrefixMap(properties, sortedAppenderNames);
+        final Map<String, String> classNameToProperty = buildClassToPropertyPrefixMap(sortedAppenderNames);
         for (final Map.Entry<String, String> entry : classNameToProperty.entrySet()) {
             final String appenderName = entry.getKey();
-            switch (entry.getValue()) {
-            case "org.apache.log4j.ConsoleAppender":
-                buildConsoleAppender(properties, appenderName, builder);
-                break;
-            default:
-                reportWarning("Ignoring appender " + appenderName
-                        + "; consider porting your configuration file to the current Log4j format.");
-            }
+            String appenderClass = entry.getValue();
+            buildAppender(appenderName, appenderClass);
         }
         // Loggers
-        buildLoggers(properties, "log4j.category.", builder);
-        buildLoggers(properties, "log4j.logger.", builder);
+        buildLoggers("log4j.category.");
+        buildLoggers("log4j.logger.");
         return builder;
     }
 
-    private Map<String, String> buildClassToPropertyPrefixMap(final Properties properties,
-                                                              final String[] sortedAppenderNames) {
+    private Map<String, String> buildClassToPropertyPrefixMap(final String[] sortedAppenderNames) {
         final String prefix = "log4j.appender.";
         final int preLength = prefix.length();
         final Map<String, String> map = new HashMap<>(sortedAppenderNames.length);
@@ -125,23 +121,56 @@ public class Log4j1ConfigurationParser {
         return map;
     }
 
-    private void buildConsoleAppender(final Properties properties, final String name,
-            final ConfigurationBuilder<BuiltConfiguration> builder) {
-        final AppenderComponentBuilder appenderBuilder = builder.newAppender(name, "Console");
-        buildConsoleAppenderTarget(properties, name, builder, appenderBuilder);
-        buildAppenderLayout(properties, name, builder, appenderBuilder);
-        buildConsoleAppenderFollow(properties, name, builder, appenderBuilder);
+    private void buildAppender(final String appenderName, final String appenderClass) {
+        switch (appenderClass) {
+        case "org.apache.log4j.ConsoleAppender":
+            buildConsoleAppender(appenderName);
+            break;
+        default:
+            reportWarning("Unknown appender class: " + appenderClass + "; ignoring appender: " + appenderName);
+        }
+    }
+
+    private void buildConsoleAppender(final String appenderName) {
+        final AppenderComponentBuilder appenderBuilder = builder.newAppender(appenderName, "Console");
+        final String targetValue = getLog4jAppenderValue(appenderName, "Target", "System.out");
+        if (targetValue != null) {
+            final ConsoleAppender.Target target;
+            switch (targetValue) {
+            case "System.out":
+                target = ConsoleAppender.Target.SYSTEM_OUT;
+                break;
+            case "System.err":
+                target = ConsoleAppender.Target.SYSTEM_ERR;
+                break;
+            default:
+                reportWarning("Unknown value for console Target: " + targetValue);
+                target = null;
+            }
+            if (target != null) {
+                appenderBuilder.addAttribute("target", target);
+            }
+        }
+        buildAppenderAttribute(appenderName, appenderBuilder, "Follow", "false", "follow");
+        buildAppenderLayout(appenderName, appenderBuilder);
         builder.add(appenderBuilder);
     }
 
-    private void buildAppenderLayout(final Properties properties, final String name,
-            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
-        final String layoutValue = getLog4jAppenderValue(properties, name, "layout", null);
-        if (layoutValue != null) {
-            switch (layoutValue) {
+    private void buildAppenderAttribute(String appenderName, AppenderComponentBuilder appenderBuilder,
+                                        String sourceAttributeName, String defaultValue, String targetAttributeName) {
+        final String attributeValue = getLog4jAppenderValue(appenderName, sourceAttributeName, defaultValue);
+        if (attributeValue != null) {
+            appenderBuilder.addAttribute(targetAttributeName, attributeValue);
+        }
+    }
+
+    private void buildAppenderLayout(final String name, final AppenderComponentBuilder appenderBuilder) {
+        final String layoutClass = getLog4jAppenderValue(name, "layout", null);
+        if (layoutClass != null) {
+            switch (layoutClass) {
             case "org.apache.log4j.PatternLayout":
             case "org.apache.log4j.EnhancedPatternLayout": {
-                final String pattern = getLog4jAppenderValue(properties, name, "layout.ConversionPattern", null)
+                final String pattern = getLog4jAppenderValue(name, "layout.ConversionPattern", null)
 
                     // Log4j 2's %x (NDC) is not compatible with Log4j 1's %x
                     //   Log4j 1: "foo bar baz"
@@ -155,55 +184,54 @@ public class Log4j1ConfigurationParser {
                     // Use %properties to get the Log4j 1 format
                     .replace("%X", "%properties");
 
-                appenderBuilder.add(newPatternLayout(builder, pattern));
+                appenderBuilder.add(newPatternLayout(pattern));
                 break;
             }
             case "org.apache.log4j.SimpleLayout": {
-                appenderBuilder.add(newPatternLayout(builder, "%level - %m%n"));
+                appenderBuilder.add(newPatternLayout("%level - %m%n"));
                 break;
             }
             case "org.apache.log4j.TTCCLayout": {
                 String pattern = "%r ";
-                if (Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.ThreadPrinting", "true"))) {
+                if (Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.ThreadPrinting", "true"))) {
                     pattern += "[%t] ";
                 }
                 pattern += "%p ";
-                if (Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.CategoryPrefixing", "true"))) {
+                if (Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.CategoryPrefixing", "true"))) {
                     pattern += "%c ";
                 }
-                if (Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.ContextPrinting", "true"))) {
+                if (Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.ContextPrinting", "true"))) {
                     pattern += "%notEmpty{%ndc }";
                 }
                 pattern += "- %m%n";
-                appenderBuilder.add(newPatternLayout(builder, pattern));
+                appenderBuilder.add(newPatternLayout(pattern));
                 break;
             }
             case "org.apache.log4j.HTMLLayout": {
                 LayoutComponentBuilder htmlLayout = builder.newLayout("HtmlLayout");
                 htmlLayout.addAttribute("title",
-                        getLog4jAppenderValue(properties, name, "layout.Title", "Log4J Log Messages"));
+                        getLog4jAppenderValue(name, "layout.Title", "Log4J Log Messages"));
                 htmlLayout.addAttribute("locationInfo",
-                        Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.LocationInfo", "false")));
+                        Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.LocationInfo", "false")));
                 appenderBuilder.add(htmlLayout);
                 break;
             }
             case "org.apache.log4j.xml.XMLLayout": {
                 LayoutComponentBuilder xmlLayout = builder.newLayout("Log4j1XmlLayout");
                 xmlLayout.addAttribute("locationInfo",
-                        Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.LocationInfo", "false")));
+                        Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.LocationInfo", "false")));
                 xmlLayout.addAttribute("properties",
-                        Boolean.parseBoolean(getLog4jAppenderValue(properties, name, "layout.Properties", "false")));
+                        Boolean.parseBoolean(getLog4jAppenderValue(name, "layout.Properties", "false")));
                 appenderBuilder.add(xmlLayout);
                 break;
             }
             default:
-                reportWarning("Unsupported layout: " + layoutValue);
+                reportWarning("Unknown layout class: " + layoutClass);
             }
         }
     }
 
-    private LayoutComponentBuilder newPatternLayout(final ConfigurationBuilder<BuiltConfiguration> builder,
-            final String pattern) {
+    private LayoutComponentBuilder newPatternLayout(final String pattern) {
         final LayoutComponentBuilder layoutBuilder = builder.newLayout("PatternLayout");
         if (pattern != null) {
             layoutBuilder.addAttribute("pattern", pattern);
@@ -211,38 +239,7 @@ public class Log4j1ConfigurationParser {
         return layoutBuilder;
     }
 
-    private void buildConsoleAppenderTarget(final Properties properties, final String name,
-            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
-        final String value = getLog4jAppenderValue(properties, name, "Target", "System.out");
-        if (value != null) {
-            final ConsoleAppender.Target target;
-            switch (value) {
-            case "System.out":
-                target = ConsoleAppender.Target.SYSTEM_OUT;
-                break;
-            case "System.err":
-                target = ConsoleAppender.Target.SYSTEM_ERR;
-                break;
-            default:
-                reportWarning("Unknow value for console Target: " + value);
-                target = null;
-            }
-            if (target != null) {
-                appenderBuilder.addAttribute("target", target);
-            }
-        }
-    }
-
-    private void buildConsoleAppenderFollow(final Properties properties, final String name,
-            final ConfigurationBuilder<BuiltConfiguration> builder, final AppenderComponentBuilder appenderBuilder) {
-        final String value = getLog4jAppenderValue(properties, name, "Follow", "false");
-        if (value != null) {
-            appenderBuilder.addAttribute("follow", Boolean.valueOf(value).booleanValue());
-        }
-    }
-
-    private String[] buildRootLogger(final ConfigurationBuilder<BuiltConfiguration> builder,
-            final String rootLoggerValue) {
+    private String[] buildRootLogger(final String rootLoggerValue) {
         if (rootLoggerValue == null) {
             return new String[0];
         }
@@ -258,8 +255,7 @@ public class Log4j1ConfigurationParser {
         return sortedAppenderNames;
     }
 
-    private void buildLoggers(final Properties properties, final String prefix,
-            final ConfigurationBuilder<BuiltConfiguration> builder) {
+    private void buildLoggers(final String prefix) {
         final int preLength = prefix.length();
         for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
             final Object keyObj = entry.getKey();
@@ -277,23 +273,15 @@ public class Log4j1ConfigurationParser {
 
     }
 
-    private String getLog4jAppenderValue(final Properties properties, final String appenderName,
-            final String attributeName, final String defaultValue) {
+    private String getLog4jAppenderValue(final String appenderName, final String attributeName,
+                                         final String defaultValue) {
         return properties.getProperty("log4j.appender." + appenderName + "." + attributeName, defaultValue);
     }
 
-    private String getLog4jValue(final Properties properties, final String key) {
+    private String getLog4jValue(final String key) {
         return properties.getProperty("log4j." + key);
     }
 
-    private String getRootCategoryValue(final Properties properties) {
-        return getLog4jValue(properties, "rootCategory");
-    }
-
-    private String getRootLoggerValue(final Properties properties) {
-        return getLog4jValue(properties, "rootLogger");
-    }
-
     private void reportWarning(final String msg) {
         StatusLogger.getLogger().warn("Log4j 1 configuration parser: " + msg);
     }


[13/18] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master'

Posted by gg...@apache.org.
Merge remote-tracking branch 'origin/master'


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/cc0bf0b4
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/cc0bf0b4
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/cc0bf0b4

Branch: refs/heads/LOG4J2-1539
Commit: cc0bf0b46232a88dc7b83a68183f6987b2809422
Parents: 3aceb2a e033027
Author: Mikael St�ldal <mi...@staldal.nu>
Authored: Thu Aug 25 22:29:13 2016 +0200
Committer: Mikael St�ldal <mi...@staldal.nu>
Committed: Thu Aug 25 22:29:13 2016 +0200

----------------------------------------------------------------------
 .../core/config/plugins/util/ResolverUtil.java  |  11 +-
 .../plugins/util/PluginManagerPackagesTest.java |   2 +-
 .../util/ResolverUtilCustomProtocolTest.java    | 208 +++++++++++++++++++
 .../config/plugins/util/ResolverUtilTest.java   | 146 +++++++------
 .../junit/URLStreamHandlerFactoryRule.java      |  96 +++++++++
 src/changes/changes.xml                         |   2 +-
 6 files changed, 400 insertions(+), 65 deletions(-)
----------------------------------------------------------------------



[11/18] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master' into LOG4J2-1547-AbstractConfiguration-with-LoggerContext

Posted by gg...@apache.org.
Merge remote-tracking branch 'origin/master' into LOG4J2-1547-AbstractConfiguration-with-LoggerContext

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/e15d0c71
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/e15d0c71
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/e15d0c71

Branch: refs/heads/LOG4J2-1539
Commit: e15d0c7126884f67dd81067e4bc939631a38ba26
Parents: 56eba73 e033027
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:20:29 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:20:29 2016 -0700

----------------------------------------------------------------------
 .../core/config/ConfigurationScheduler.java     |   2 +-
 .../core/config/plugins/util/ResolverUtil.java  |  11 +-
 .../apache/logging/log4j/core/jmx/Server.java   |   4 +
 .../RollingAppenderCronOnceADayTest.java        | 128 ++++++++++++
 .../plugins/util/PluginManagerPackagesTest.java |   2 +-
 .../util/ResolverUtilCustomProtocolTest.java    | 208 +++++++++++++++++++
 .../config/plugins/util/ResolverUtilTest.java   | 146 +++++++------
 .../junit/URLStreamHandlerFactoryRule.java      |  96 +++++++++
 .../resources/log4j-rolling-cron-once-a-day.xml |  47 +++++
 .../src/test/resources/log4j-rolling-cron.xml   |   2 +-
 .../src/test/resources/log4j-rolling-cron2.xml  |   2 +-
 src/changes/changes.xml                         |   5 +-
 12 files changed, 585 insertions(+), 68 deletions(-)
----------------------------------------------------------------------



[15/18] logging-log4j2 git commit: Better lvarnames.

Posted by gg...@apache.org.
Better lvarnames.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/acbecc0b
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/acbecc0b
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/acbecc0b

Branch: refs/heads/LOG4J2-1539
Commit: acbecc0bd14474a63ef09abb4e301048f9b6518f
Parents: 1db38fc
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 13:58:11 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 13:58:11 2016 -0700

----------------------------------------------------------------------
 .../log4j/core/config/plugins/util/ResolverUtilTest.java  | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/acbecc0b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
index 92e6ee9..f5d13eb 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/util/ResolverUtilTest.java
@@ -168,10 +168,10 @@ public class ResolverUtilTest {
     static URLClassLoader compileJarAndCreateClassLoader(String suffix) throws IOException, Exception {
         File workDir = compile(suffix);
         File jarFile = new File(workDir, "customplugin" + suffix + ".jar");
-        URI jarURL = jarFile.toURI();
-        createJar(jarURL, workDir, new File(workDir,
+        URI jarURI = jarFile.toURI();
+        createJar(jarURI, workDir, new File(workDir,
               "customplugin" + suffix + "/FixedString" + suffix + "Layout.class"));
-        return URLClassLoader.newInstance(new URL[] {jarURL.toURL()});
+        return URLClassLoader.newInstance(new URL[] {jarURI.toURL()});
     }
 
     static URLClassLoader compileAndCreateClassLoader(String suffix) throws IOException {
@@ -197,10 +197,10 @@ public class ResolverUtilTest {
         return workDir;
     }
 
-    static void createJar(URI jarURL, File workDir, File f) throws Exception {
+    static void createJar(URI jarURI, File workDir, File f) throws Exception {
         Map<String, String> env = new HashMap<>(); 
         env.put("create", "true");
-        URI uri = URI.create("jar:file://" + jarURL.getPath());
+        URI uri = URI.create("jar:file://" + jarURI.getPath());
         try (FileSystem zipfs = FileSystems.newFileSystem(uri, env)) {   
             Path path = zipfs.getPath(workDir.toPath().relativize(f.toPath()).toString());
             if (path.getParent() != null) {


[05/18] logging-log4j2 git commit: [LOG4J2-1548][CronTriggeringPolicy] ConfigurationScheduler schedules the task infinitely after first fire. Heads-up: The new test has a TODO noting that the test uses Thread.sleep() all over the place; it takes about a

Posted by gg...@apache.org.
[LOG4J2-1548][CronTriggeringPolicy] ConfigurationScheduler schedules the
task infinitely after first fire. Heads-up: The new test has a TODO
noting that the test uses Thread.sleep() all over the place; it takes
about a minute to run. Expect a 1-minute slower build until a better
test is in place. Note that the part of the patch related to
ResolverUtil was not applied.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33aaf3d5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33aaf3d5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33aaf3d5

Branch: refs/heads/LOG4J2-1539
Commit: 33aaf3d52503a3c5781a30424994ad1b5907d59e
Parents: 8b40c1f
Author: Gary Gregory <gg...@apache.org>
Authored: Wed Aug 24 08:51:39 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Wed Aug 24 08:51:39 2016 -0700

----------------------------------------------------------------------
 .../core/config/ConfigurationScheduler.java     |   2 +-
 .../RollingAppenderCronOnceADayTest.java        | 128 +++++++++++++++++++
 .../resources/log4j-rolling-cron-once-a-day.xml |  47 +++++++
 .../src/test/resources/log4j-rolling-cron.xml   |   2 +-
 .../src/test/resources/log4j-rolling-cron2.xml  |   2 +-
 src/changes/changes.xml                         |   3 +
 6 files changed, 181 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java
index 744ed24..e6291f9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java
@@ -182,7 +182,7 @@ public class ConfigurationScheduler extends AbstractLifeCycle {
             } catch(final Throwable ex) {
                 LOGGER.error("Error running command", ex);
             } finally {
-                Date fireDate = cronExpression.getNextInvalidTimeAfter(new Date());
+                Date fireDate = cronExpression.getNextValidTimeAfter(new Date());
                 final ScheduledFuture<?> future = schedule(this, nextFireInterval(fireDate), TimeUnit.MILLISECONDS);
                 scheduledFuture.reset(future, fireDate);
             }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronOnceADayTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronOnceADayTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronOnceADayTest.java
new file mode 100644
index 0000000..2e091c4
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/rolling/RollingAppenderCronOnceADayTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.core.appender.rolling;
+
+import static org.apache.logging.log4j.hamcrest.Descriptors.that;
+import static org.apache.logging.log4j.hamcrest.FileMatchers.hasName;
+import static org.hamcrest.Matchers.endsWith;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Calendar;
+
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.appender.RollingFileAppender;
+import org.apache.logging.log4j.core.util.CronExpression;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.apache.logging.log4j.status.StatusLogger;
+import org.hamcrest.Matcher;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.RuleChain;
+
+/**
+ * This test currently takes about a minute to run.
+ */
+public class RollingAppenderCronOnceADayTest {
+
+    private static final String UTF_8 = "UTF-8";
+    private static final String CONFIG = "log4j-rolling-cron-once-a-day.xml";
+    private static final String CONFIG_TARGET = "log4j-rolling-cron-once-a-day-target.xml";
+    private static final String TARGET = "target";
+    private static final String DIR = TARGET + "/rolling-cron-once-a-day";
+    private static final String FILE = DIR + "/rollingtest.log";
+    private static final String TARGET_TEST_CLASSES = TARGET + "/test-classes";
+
+    private static String cronExpression;
+    private static long remainingTime;
+
+    @BeforeClass
+    public static void beforeClass() throws Exception {
+      final Path src = FileSystems.getDefault().getPath(TARGET_TEST_CLASSES, CONFIG);
+      String content = new String(Files.readAllBytes(src), UTF_8);
+      Calendar cal = Calendar.getInstance();
+      cal.add(Calendar.SECOND, 45);
+      remainingTime = cal.getTimeInMillis() - System.currentTimeMillis();
+      cronExpression =  String.format("%d %d %d * * ?",
+          cal.get(Calendar.SECOND),
+          cal.get(Calendar.MINUTE),
+          cal.get(Calendar.HOUR_OF_DAY));
+      content = content.replace("@CRON_EXPR@", cronExpression);
+      Files.write(FileSystems.getDefault()
+            .getPath(TARGET_TEST_CLASSES, CONFIG_TARGET), content.getBytes(UTF_8));
+      StatusLogger.getLogger().debug("Cron expression will be " + cronExpression + " in " + remainingTime + "ms");
+    }
+
+    private final LoggerContextRule loggerContextRule = new LoggerContextRule(CONFIG_TARGET);
+
+    @Rule
+    public RuleChain chain = loggerContextRule.withCleanFoldersRule(true, false, 1, DIR);
+
+    @Test
+    public void testAppender() throws Exception {
+        // TODO Is there a better way to test than putting the thread to sleep all over the place?
+        final Logger logger = loggerContextRule.getLogger();
+        File file = new File(FILE);
+        assertTrue("Log file does not exist", file.exists());
+        logger.debug("This is test message number 1, waiting for rolling");
+
+        final RollingFileAppender app = (RollingFileAppender) loggerContextRule.getContext().getConfiguration().getAppender("RollingFile");
+        final TriggeringPolicy policy = app.getManager().getTriggeringPolicy();
+        assertNotNull("No triggering policy", policy);
+        assertTrue("Incorrect policy type", policy instanceof CronTriggeringPolicy);
+        final CronExpression expression = ((CronTriggeringPolicy) policy).getCronExpression();
+        assertEquals("Incorrect cron expresion", cronExpression, expression.getCronExpression());
+        logger.debug("Cron expression will be {}", expression.getCronExpression());
+
+        // force a reconfiguration
+        for (int i = 1; i <= 20; ++i) {
+            logger.debug("Adding first event {}", i);
+        }
+
+        Thread.sleep(remainingTime);
+        final File dir = new File(DIR);
+        assertTrue("Directory not created", dir.exists() && dir.listFiles().length > 0);
+
+        for (int i = 1; i < 20; i++) {
+          logger.debug("Adding again event {}", i);
+        }
+        Thread.sleep(1000);
+        for (int i = 1; i < 10; i++) {
+          logger.debug("Adding some more event {}", i);
+          Thread.sleep(1000);
+        }
+        final Matcher<File> hasGzippedFile = hasName(that(endsWith(".gz")));
+        int count = 0;
+        final File[] files = dir.listFiles();
+        for (File generatedFile : files) {
+          if (hasGzippedFile.matches(generatedFile)) {
+              count++;
+          }
+        }
+
+        assertNotEquals("No compressed files found", 0, count);
+        assertEquals("Multiple files found" , 1, count);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/log4j-core/src/test/resources/log4j-rolling-cron-once-a-day.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-cron-once-a-day.xml b/log4j-core/src/test/resources/log4j-rolling-cron-once-a-day.xml
new file mode 100644
index 0000000..9d71fc9
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-rolling-cron-once-a-day.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<Configuration status="ERROR" name="RollingCronTestOnceADay">
+  <Properties>
+    <Property name="filename">target/rolling-cron-once-a-day/rollingtest.log</Property>
+  </Properties>
+
+  <Appenders>
+    <Console name="STDOUT" target="SYSTEM_OUT">
+      <PatternLayout pattern="%p %C{1.} [%t] %m%n"/>
+    </Console>
+    <RollingFile name="RollingFile"
+    	 fileName="${filename}"
+    	 filePattern="target/rolling-cron-once-a-day/rollingtest-%d{yyyyMMdd}_%d{HHmmss}-%i.log.gz"
+    	 immediateFlush="true">
+      <PatternLayout pattern="%d %p %C{1.} [%t] %m%n" />
+      <CronTriggeringPolicy schedule="@CRON_EXPR@"/>
+    </RollingFile>
+  </Appenders>
+
+  <Loggers>
+    <Logger name="org.apache.logging.log4j.core.appender.rolling" level="DEBUG" additivity="false">
+      <AppenderRef ref="RollingFile"/>
+    </Logger>
+
+    <Root level="ERROR">
+      <AppenderRef ref="STDOUT"/>
+    </Root>
+  </Loggers>
+
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/log4j-core/src/test/resources/log4j-rolling-cron.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-cron.xml b/log4j-core/src/test/resources/log4j-rolling-cron.xml
index 9579804..be6fa70 100644
--- a/log4j-core/src/test/resources/log4j-rolling-cron.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-cron.xml
@@ -44,7 +44,7 @@
   <Loggers>
     <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
       <AppenderRef ref="RollingFile"/>
-    </Logger>>
+    </Logger>
 
     <Root level="error">
       <AppenderRef ref="STDOUT"/>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/log4j-core/src/test/resources/log4j-rolling-cron2.xml
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-rolling-cron2.xml b/log4j-core/src/test/resources/log4j-rolling-cron2.xml
index a6a17ed..9110f50 100644
--- a/log4j-core/src/test/resources/log4j-rolling-cron2.xml
+++ b/log4j-core/src/test/resources/log4j-rolling-cron2.xml
@@ -44,7 +44,7 @@
   <Loggers>
     <Logger name="org.apache.logging.log4j.core.appender.rolling" level="debug" additivity="false">
       <AppenderRef ref="RollingFile"/>
-    </Logger>>
+    </Logger>
 
     <Root level="error">
       <AppenderRef ref="STDOUT"/>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33aaf3d5/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 776da03..dbc3310 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
   </properties>
   <body>
     <release version="2.7" date="2016-MM-DD" description="GA Release 2.7">
+      <action issue="LOG4J2-1548" dev="ggregory" type="fix" due-to="Gary Gregory">
+        [CronTriggeringPolicy] ConfigurationScheduler schedules the task infinitely after first fire.
+      </action>
       <action issue="LOG4J2-1506" dev="ggregory" type="fix" due-to="Johannes Schleger">
         Unregister JMX ignores log4j2.disable.jmx property.
       </action>


[18/18] logging-log4j2 git commit: Merge remote-tracking branch 'origin/master' into LOG4J2-1539

Posted by gg...@apache.org.
Merge remote-tracking branch 'origin/master' into LOG4J2-1539

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/a4ef9a1d
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/a4ef9a1d
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/a4ef9a1d

Branch: refs/heads/LOG4J2-1539
Commit: a4ef9a1de092e8f4748716e62dff0d6972c1bcb1
Parents: d18e9c9 29e7bfd
Author: Gary Gregory <gg...@apache.org>
Authored: Thu Aug 25 14:43:20 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Thu Aug 25 14:43:20 2016 -0700

----------------------------------------------------------------------
 .../config/Log4j1ConfigurationFactory.java      |    9 +-
 .../log4j/config/Log4j1ConfigurationParser.java |  210 ++--
 .../apache/log4j/BasicConfigurationFactory.java |   13 +-
 .../config/Log4j1ConfigurationFactoryTest.java  |   29 +-
 ...g4j-console-EnhancedPatternLayout.properties |    1 -
 .../log4j-console-HtmlLayout.properties         |    1 -
 .../log4j-console-PatternLayout.properties      |    1 -
 .../log4j-console-SimpleLayout.properties       |    1 -
 .../log4j-console-TTCCLayout.properties         |    1 -
 .../log4j-console-XmlLayout.properties          |    1 -
 .../log4j-file-SimpleLayout.properties          |   17 +
 .../logging/log4j/core/LoggerContext.java       |    2 +-
 .../core/config/AbstractConfiguration.java      |   15 +-
 .../log4j/core/config/Configuration.java        |    8 +
 .../log4j/core/config/ConfigurationFactory.java | 1113 +++++++++---------
 .../core/config/ConfigurationScheduler.java     |    2 +-
 .../log4j/core/config/DefaultConfiguration.java |    2 +-
 .../log4j/core/config/NullConfiguration.java    |    2 +-
 .../builder/api/ConfigurationBuilder.java       |    8 +
 .../config/builder/impl/BuiltConfiguration.java |    5 +-
 .../impl/DefaultConfigurationBuilder.java       |   29 +-
 .../composite/CompositeConfiguration.java       |    4 +-
 .../core/config/json/JsonConfiguration.java     |   14 +-
 .../config/json/JsonConfigurationFactory.java   |    5 +-
 .../core/config/plugins/util/ResolverUtil.java  |   11 +-
 .../properties/PropertiesConfiguration.java     |    8 +-
 .../PropertiesConfigurationBuilder.java         |   16 +-
 .../PropertiesConfigurationFactory.java         |   10 +-
 .../log4j/core/config/xml/XmlConfiguration.java |    7 +-
 .../config/xml/XmlConfigurationFactory.java     |    5 +-
 .../core/config/yaml/YamlConfiguration.java     |    7 +-
 .../config/yaml/YamlConfigurationFactory.java   |    5 +-
 .../log4j/core/impl/Log4jContextFactory.java    |    6 +-
 .../log4j/core/jmx/LoggerContextAdmin.java      |    4 +-
 .../apache/logging/log4j/core/jmx/Server.java   |    4 +
 .../core/net/server/AbstractSocketServer.java   |    7 +-
 .../log4j/core/BasicConfigurationFactory.java   |    6 +-
 .../RollingAppenderCronOnceADayTest.java        |  128 ++
 .../log4j/core/config/ConfigurationTest.java    |    6 +
 .../builder/CustomConfigurationFactory.java     |   11 +-
 .../plugins/util/PluginManagerPackagesTest.java |    2 +-
 .../util/ResolverUtilCustomProtocolTest.java    |  208 ++++
 .../config/plugins/util/ResolverUtilTest.java   |  146 ++-
 .../junit/URLStreamHandlerFactoryRule.java      |   96 ++
 .../resources/log4j-rolling-cron-once-a-day.xml |   47 +
 .../src/test/resources/log4j-rolling-cron.xml   |    2 +-
 .../src/test/resources/log4j-rolling-cron2.xml  |    2 +-
 .../configuration/CustomConfiguration.java      |   13 +-
 .../CustomConfigurationFactory.java             |   12 +-
 src/changes/changes.xml                         |    8 +-
 50 files changed, 1464 insertions(+), 806 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a4ef9a1d/log4j-core/src/main/java/org/apache/logging/log4j/core/LoggerContext.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a4ef9a1d/log4j-core/src/main/java/org/apache/logging/log4j/core/config/ConfigurationScheduler.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a4ef9a1d/log4j-core/src/main/java/org/apache/logging/log4j/core/jmx/Server.java
----------------------------------------------------------------------