From 72a22e6a1096fefecb61446dc20331e48ed7b897 Mon Sep 17 00:00:00 2001
From: mck <mick@semb.wever.org>
Date: Thu, 19 Jun 2014 22:20:14 +0200
Subject: [PATCH] =?UTF-8?q?LOG4J2-673=20=E2=80=93=20plugin=20preloading=20?=
 =?UTF-8?q?fails=20in=20shaded=20jar=20files=20Support=20for=20plugin=20pr?=
 =?UTF-8?q?eloading=20through=20the=20standard=20javax.annotation.processi?=
 =?UTF-8?q?ng=20tool=20was=20adding=20in=20LOG4J2-595?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

But the plugin processor always creates and stores the processed "Plugin" annotated classes into the same file. This works fine when the classpath consists of individual jar files, but fails when shaded jar files are used.

The fix saves the dat file in a location under META-INF that matches the shared package all the processed plugins are found under.
The package attribute in the config file is then used so that multiple dat files can be loaded at runtime.
This means that the package attribute is no longer deprecated.
---
 .../config/plugins/processor/PluginProcessor.java  | 37 ++++++++++++++++++++--
 .../core/config/plugins/util/PluginManager.java    | 30 ++++++++++++++----
 .../plugins/processor/PluginProcessorTest.java     |  3 +-
 .../AsyncLoggersWithAsyncAppenderTest.xml          |  4 +--
 .../AsyncLoggersWithAsyncLoggerConfigTest.xml      |  4 +--
 log4j-core/src/test/resources/log4j-Level.xml      |  2 +-
 log4j-core/src/test/resources/log4j-advertiser.xml |  2 +-
 .../test/resources/log4j-asynch-no-location.xml    |  2 +-
 log4j-core/src/test/resources/log4j-asynch.xml     |  2 +-
 log4j-core/src/test/resources/log4j-burst.xml      |  2 +-
 .../src/test/resources/log4j-collectionLogging.xml |  2 +-
 .../src/test/resources/log4j-customLevel.xml       |  2 +-
 log4j-core/src/test/resources/log4j-failover.xml   |  2 +-
 .../src/test/resources/log4j-jmsqueue-failover.xml |  2 +-
 .../src/test/resources/log4j-jmstopic-failover.xml |  2 +-
 .../src/test/resources/log4j-loggerprops.xml       |  2 +-
 .../src/test/resources/log4j-reference-level.json  |  2 +-
 .../src/test/resources/log4j-reference-level.xml   |  2 +-
 log4j-core/src/test/resources/log4j-replace.xml    |  2 +-
 log4j-core/src/test/resources/log4j-rewrite.xml    |  2 +-
 .../test/resources/log4j-rootthrowablefilter.xml   |  2 +-
 .../src/test/resources/log4j-routing-by-jndi.xml   |  2 +-
 log4j-core/src/test/resources/log4j-routing.json   |  2 +-
 log4j-core/src/test/resources/log4j-routing.xml    |  2 +-
 log4j-core/src/test/resources/log4j-routing2.json  |  2 +-
 log4j-core/src/test/resources/log4j-routing3.xml   |  2 +-
 log4j-core/src/test/resources/log4j-strict1.xml    |  2 +-
 log4j-core/src/test/resources/log4j-style.xml      |  2 +-
 log4j-core/src/test/resources/log4j-test1.json     |  1 +
 log4j-core/src/test/resources/log4j-test1.xml      |  2 +-
 log4j-core/src/test/resources/log4j-test1.yaml     |  1 +
 log4j-core/src/test/resources/log4j-test2.xml      |  2 +-
 log4j-core/src/test/resources/log4j-throwable.xml  |  2 +-
 .../src/test/resources/log4j-throwablefilter.xml   |  2 +-
 .../src/test/resources/log4j2-calling-class.xml    |  2 +-
 log4j-core/src/test/resources/log4j2-config.xml    |  2 +-
 log4j-core/src/test/resources/log4j2-mapfilter.xml |  2 +-
 .../src/test/resources/missingRootLogger.xml       |  2 +-
 log4j-jcl/src/test/resources/log4j-test1.xml       |  2 +-
 .../src/test/resources/log4j-test1.xml             |  2 +-
 log4j-taglib/src/test/resources/log4j-test1.xml    |  2 +-
 41 files changed, 101 insertions(+), 47 deletions(-)

diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
index 2a00846..44f9fe9 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
@@ -56,10 +56,19 @@ public class PluginProcessor extends AbstractProcessor {
      * The location of the plugin cache data file. This file is written to by this processor, and read from by
      * {@link org.apache.logging.log4j.core.config.plugins.util.PluginManager}.
      */
-    public static final String PLUGIN_CACHE_FILE = "META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat";
+    private static final String PLUGIN_DEFAULT_PACKAGE = "org.apache.logging.log4j.core.config.plugins";
+    public static final String PLUGIN_CACHE_FILE = getResourceNameForPackage(PLUGIN_DEFAULT_PACKAGE);
 
     private final PluginCache pluginCache = new PluginCache();
 
+    public static String getResourceNameForPackage(final String packge) {
+        if (packge.isEmpty()) {
+            throw new IllegalArgumentException(
+                    "All annotated @Plugin classes must reside in a common non-default parent package");
+        }
+        return ("META-INF/" + packge.replace('.', '/') + "/Log4j2Plugins.dat").replace("//", "/");
+    }
+
     @Override
     public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
         try {
@@ -99,8 +108,10 @@ public class PluginProcessor extends AbstractProcessor {
     }
 
     private void writeCacheFile(final Element... elements) throws IOException {
+        final String basePackage = findSharedPrefix(elements);
+        final String cacheFile = getResourceNameForPackage(basePackage);
         final FileObject fo = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT,
-            Strings.EMPTY, PLUGIN_CACHE_FILE, elements);
+            Strings.EMPTY, cacheFile, elements);
         final OutputStream out = fo.openOutputStream();
         try {
             pluginCache.writeCache(out);
@@ -109,6 +120,28 @@ public class PluginProcessor extends AbstractProcessor {
         }
     }
 
+    private String findSharedPrefix(final Element... elements) {
+        assert 0 != elements.length : "need at least one entry";
+        CharSequence result = "";
+        for(int i = 0 ; i < elements.length ; ++i) {
+            CharSequence string = processingEnv.getElementUtils().getPackageOf(elements[i]).getQualifiedName();
+            result = 0 == i ? string : findSharedPrefix(result, string);
+        }
+        return "org.apache.logging.log4j.core.".equals(result.toString())
+                ? PLUGIN_DEFAULT_PACKAGE
+                : result.toString();
+    }
+
+    private static CharSequence findSharedPrefix(final CharSequence a, final CharSequence b) {
+        int minLength = Math.min(a.length(), b.length());
+        for (int i = 0; i < minLength; i++) {
+            if (a.charAt(i) != b.charAt(i)) {
+                return a.subSequence(0, i);
+            }
+        }
+        return a.subSequence(0, minLength);
+    }
+
     /**
      * ElementVisitor to scan the Plugin annotation.
      */
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginManager.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginManager.java
index 4e85baa..fc2dddb 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginManager.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/util/PluginManager.java
@@ -21,10 +21,14 @@ import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.core.config.plugins.processor.PluginProcessor;
@@ -43,6 +47,10 @@ public class PluginManager {
     private static final PluginRegistry<PluginType<?>> REGISTRY =
         new PluginRegistry<PluginType<?>>();
 
+    private static final List<String> RESOURCES = new CopyOnWriteArrayList<String>() {{
+        add(PluginProcessor.PLUGIN_CACHE_FILE);
+    }};
+
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     private Map<String, PluginType<?>> plugins = new HashMap<String, PluginType<?>>();
@@ -73,8 +81,8 @@ public class PluginManager {
      * Adds a package name to be scanned for plugins. Must be invoked prior to plugins being collected.
      * @param p The package name.
      */
-    @Deprecated // no more need for this method due to PluginProcessor
     public static void addPackage(final String p) {
+        RESOURCES.add(PluginProcessor.getResourceNameForPackage(p));
     }
 
     /**
@@ -130,10 +138,10 @@ public class PluginManager {
     }
 
     private static PluginRegistry<PluginType<?>> decode(final ResourceLoader loader) {
-        final Enumeration<URL> resources;
+        final List<URL> resources;
         try {
-            resources = loader.getResources(PluginProcessor.PLUGIN_CACHE_FILE);
-            if (resources == null) {
+            resources = preloadResources(loader);
+            if (resources.isEmpty()) {
                 return null;
             }
         } catch (final IOException ioe) {
@@ -141,8 +149,7 @@ public class PluginManager {
             return null;
         }
         final PluginRegistry<PluginType<?>> map = new PluginRegistry<PluginType<?>>();
-        while (resources.hasMoreElements()) {
-            final URL url = resources.nextElement();
+        for (URL url : resources) {
             LOGGER.debug("Found Plugin Map at {}", url.toExternalForm());
             final InputStream is;
             try {
@@ -183,4 +190,15 @@ public class PluginManager {
         return map.isEmpty() ? null : map;
     }
 
+    private static List<URL> preloadResources(final ResourceLoader loader) throws IOException {
+        final List<URL> resources = new ArrayList<URL>();
+        for(String resource : RESOURCES) {
+            Enumeration<URL> e = loader.getResources(resource);
+            if (null != e) {
+                resources.addAll(Collections.list(e));
+            }
+        }
+        return resources;
+    }
+
 }
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
index 06ebded..77516c1 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
@@ -34,13 +34,14 @@ import static org.junit.Assert.*;
 public class PluginProcessorTest {
 
     private static final PluginCache pluginCache = new PluginCache();
+    private static final String PLUGIN_CACHE_FILE = PluginProcessor.getResourceNameForPackage("org.apache.logging.log4j");
 
     private final Plugin p = FakePlugin.class.getAnnotation(Plugin.class);
 
     @BeforeClass
     public static void setUpClass() throws Exception {
         final Enumeration<URL> resources =
-            PluginProcessor.class.getClassLoader().getResources(PluginProcessor.PLUGIN_CACHE_FILE);
+            PluginProcessor.class.getClassLoader().getResources(PLUGIN_CACHE_FILE);
         pluginCache.loadCacheFiles(resources);
     }
 
diff --git a/log4j-core/src/test/resources/AsyncLoggersWithAsyncAppenderTest.xml b/log4j-core/src/test/resources/AsyncLoggersWithAsyncAppenderTest.xml
index 0775cde..1aa9ab3 100644
--- a/log4j-core/src/test/resources/AsyncLoggersWithAsyncAppenderTest.xml
+++ b/log4j-core/src/test/resources/AsyncLoggersWithAsyncAppenderTest.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="ERROR">
+<Configuration status="ERROR"  packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List">
       <PatternLayout pattern="%c %m"/>
@@ -8,7 +8,7 @@
       <AppenderRef ref="List"/>
     </Async>
   </Appenders>
-  
+
   <Loggers>
     <Root level="trace">
       <AppenderRef ref="Async"/>
diff --git a/log4j-core/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml b/log4j-core/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml
index 131a22a..00806ab 100644
--- a/log4j-core/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml
+++ b/log4j-core/src/test/resources/AsyncLoggersWithAsyncLoggerConfigTest.xml
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Configuration status="ERROR">
+<Configuration status="ERROR" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List">
       <PatternLayout pattern="%c %m"/>
     </List>
   </Appenders>
-  
+
   <Loggers>
     <AsyncRoot level="trace">
       <AppenderRef ref="List"/>
diff --git a/log4j-core/src/test/resources/log4j-Level.xml b/log4j-core/src/test/resources/log4j-Level.xml
index 9e7ae8f..95758df 100644
--- a/log4j-core/src/test/resources/log4j-Level.xml
+++ b/log4j-core/src/test/resources/log4j-Level.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-advertiser.xml b/log4j-core/src/test/resources/log4j-advertiser.xml
index b66c0fc..e769e3a 100644
--- a/log4j-core/src/test/resources/log4j-advertiser.xml
+++ b/log4j-core/src/test/resources/log4j-advertiser.xml
@@ -17,7 +17,7 @@
 
 -->
 <Configuration status="OFF" dest="target/status.log" name="XMLConfigTest"
-               advertiser="memory">
+               advertiser="memory" packages="org.apache.logging.log4j">
   <ThresholdFilter level="debug"/>
 
   <Appenders>
diff --git a/log4j-core/src/test/resources/log4j-asynch-no-location.xml b/log4j-core/src/test/resources/log4j-asynch-no-location.xml
index 8db42cc..85a5af0 100644
--- a/log4j-core/src/test/resources/log4j-asynch-no-location.xml
+++ b/log4j-core/src/test/resources/log4j-asynch-no-location.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingTest">
+<Configuration status="OFF" name="RoutingTest"  packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-asynch.xml b/log4j-core/src/test/resources/log4j-asynch.xml
index 16a6793..e581af1 100644
--- a/log4j-core/src/test/resources/log4j-asynch.xml
+++ b/log4j-core/src/test/resources/log4j-asynch.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingTest">
+<Configuration status="OFF" name="RoutingTest" packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-burst.xml b/log4j-core/src/test/resources/log4j-burst.xml
index 205a579..c13de44 100644
--- a/log4j-core/src/test/resources/log4j-burst.xml
+++ b/log4j-core/src/test/resources/log4j-burst.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="BurstTest">
+<Configuration status="OFF" name="BurstTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="ListAppender">
       <PatternLayout pattern="%-5p %d{dd-MMM-yyyy HH:mm:ss} %t %m%n"/>
diff --git a/log4j-core/src/test/resources/log4j-collectionLogging.xml b/log4j-core/src/test/resources/log4j-collectionLogging.xml
index cc0a99b..a3d4bf4 100644
--- a/log4j-core/src/test/resources/log4j-collectionLogging.xml
+++ b/log4j-core/src/test/resources/log4j-collectionLogging.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-customLevel.xml b/log4j-core/src/test/resources/log4j-customLevel.xml
index a80d07d..1c8f24b 100644
--- a/log4j-core/src/test/resources/log4j-customLevel.xml
+++ b/log4j-core/src/test/resources/log4j-customLevel.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-failover.xml b/log4j-core/src/test/resources/log4j-failover.xml
index e71cab7..84568f7 100644
--- a/log4j-core/src/test/resources/log4j-failover.xml
+++ b/log4j-core/src/test/resources/log4j-failover.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="FailoverTest">
+<Configuration status="OFF" name="FailoverTest" packages="org.apache.logging.log4j">
   <Appenders>
     <AlwaysFail name="Fail" />
     <FailOnce name="Once"/>
diff --git a/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml b/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
index 8b86750..d620916 100644
--- a/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
+++ b/log4j-core/src/test/resources/log4j-jmsqueue-failover.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="FailoverTest">
+<Configuration status="OFF" name="FailoverTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List"/>
     <JMSQueue name="Log4j2Queue" queueBindingName="Log4j2Queue" factoryBindingName="QueueConnectionFactory"
diff --git a/log4j-core/src/test/resources/log4j-jmstopic-failover.xml b/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
index 8588f69..933985d 100644
--- a/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
+++ b/log4j-core/src/test/resources/log4j-jmstopic-failover.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="FailoverTest">
+<Configuration status="OFF" name="FailoverTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List"/>
     <JMSTopic name="Log4j2Topic" topicBindingName="Log4j2Topic" factoryBindingName="TopicConnectionFactory"
diff --git a/log4j-core/src/test/resources/log4j-loggerprops.xml b/log4j-core/src/test/resources/log4j-loggerprops.xml
index daa7439..5e069ff 100644
--- a/log4j-core/src/test/resources/log4j-loggerprops.xml
+++ b/log4j-core/src/test/resources/log4j-loggerprops.xml
@@ -15,7 +15,7 @@
   ~ See the License for the specific language governing permissions and
   ~ limitations under the License.
   -->
-<Configuration status="OFF" strict="false" name="DSI">
+<Configuration status="OFF" strict="false" name="DSI" packages="org.apache.logging.log4j">
   <Properties>
      <Property name="test2">test2default</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-reference-level.json b/log4j-core/src/test/resources/log4j-reference-level.json
index 37586c4..7b4e3b4 100644
--- a/log4j-core/src/test/resources/log4j-reference-level.json
+++ b/log4j-core/src/test/resources/log4j-reference-level.json
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-{ "configuration": { "status": "error", "XMLConfigTest": "RoutingTest",
+{ "configuration": { "status": "error", "XMLConfigTest": "RoutingTest", "packages": "org.apache.logging.log4j",
     "appenders": {
         "appender": [
             { "type": "Console", "name": "STDOUT", "PatternLayout": { "pattern": "%m%n" }},
diff --git a/log4j-core/src/test/resources/log4j-reference-level.xml b/log4j-core/src/test/resources/log4j-reference-level.xml
index 2d3ae6a..3450e73 100644
--- a/log4j-core/src/test/resources/log4j-reference-level.xml
+++ b/log4j-core/src/test/resources/log4j-reference-level.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Appenders>
     <Console name="STDOUT">
       <PatternLayout pattern="%m%n"/>
diff --git a/log4j-core/src/test/resources/log4j-replace.xml b/log4j-core/src/test/resources/log4j-replace.xml
index 09ff3b1..a378f29 100644
--- a/log4j-core/src/test/resources/log4j-replace.xml
+++ b/log4j-core/src/test/resources/log4j-replace.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RegexReplacementTest">
+<Configuration status="OFF" name="RegexReplacementTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List">
        <PatternLayout>
diff --git a/log4j-core/src/test/resources/log4j-rewrite.xml b/log4j-core/src/test/resources/log4j-rewrite.xml
index 3fee0ec..cfafe66 100644
--- a/log4j-core/src/test/resources/log4j-rewrite.xml
+++ b/log4j-core/src/test/resources/log4j-rewrite.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingTest">
+<Configuration status="OFF" name="RoutingTest" packages="org.apache.logging.log4j">
 
   <Appenders>
     <Console name="STDOUT">
diff --git a/log4j-core/src/test/resources/log4j-rootthrowablefilter.xml b/log4j-core/src/test/resources/log4j-rootthrowablefilter.xml
index 9c8f0e5..35171ea 100644
--- a/log4j-core/src/test/resources/log4j-rootthrowablefilter.xml
+++ b/log4j-core/src/test/resources/log4j-rootthrowablefilter.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filters">org.junit,org.apache.maven,sun.reflect,java.lang.reflect</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-routing-by-jndi.xml b/log4j-core/src/test/resources/log4j-routing-by-jndi.xml
index 2967eaa..5eed814 100644
--- a/log4j-core/src/test/resources/log4j-routing-by-jndi.xml
+++ b/log4j-core/src/test/resources/log4j-routing-by-jndi.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingByJndiTest">
+<Configuration status="OFF" name="RoutingByJndiTest" packages="org.apache.logging.log4j">
 
   <ThresholdFilter level="debug"/>
 
diff --git a/log4j-core/src/test/resources/log4j-routing.json b/log4j-core/src/test/resources/log4j-routing.json
index 809b3c2..ed20338 100644
--- a/log4j-core/src/test/resources/log4j-routing.json
+++ b/log4j-core/src/test/resources/log4j-routing.json
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-{ "configuration": { "status": "error", "name": "RoutingTest",
+{ "configuration": { "status": "error", "name": "RoutingTest", "packages": "org.apache.logging.log4j",
       "properties": {
         "property": { "name": "filename", "value" : "target/rolling1/rollingtest-$${sd:type}.log" }
       },
diff --git a/log4j-core/src/test/resources/log4j-routing.xml b/log4j-core/src/test/resources/log4j-routing.xml
index 4d83886..1ce4a75 100644
--- a/log4j-core/src/test/resources/log4j-routing.xml
+++ b/log4j-core/src/test/resources/log4j-routing.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingTest">
+<Configuration status="OFF" name="RoutingTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filename">target/routing1/routingtest-$${sd:type}.log</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-routing2.json b/log4j-core/src/test/resources/log4j-routing2.json
index fe50b37..86ef8d1 100644
--- a/log4j-core/src/test/resources/log4j-routing2.json
+++ b/log4j-core/src/test/resources/log4j-routing2.json
@@ -14,7 +14,7 @@
  * See the license for the specific language governing permissions and
  * limitations under the license.
  */
-{ "configuration": { "status": "error", "name": "RoutingTest",
+{ "configuration": { "status": "error", "name": "RoutingTest",  "packages": "org.apache.logging.log4j",
       "properties": {
         "property": { "name": "filename", "value" : "target/rolling1/rollingtest-$${sd:type}.log" }
       },
diff --git a/log4j-core/src/test/resources/log4j-routing3.xml b/log4j-core/src/test/resources/log4j-routing3.xml
index a35c9d0..6c05b21 100644
--- a/log4j-core/src/test/resources/log4j-routing3.xml
+++ b/log4j-core/src/test/resources/log4j-routing3.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="RoutingTest">
+<Configuration status="OFF" name="RoutingTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filename">target/routing1/routingtest.log</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-strict1.xml b/log4j-core/src/test/resources/log4j-strict1.xml
index 9b000b7..ee324aa 100644
--- a/log4j-core/src/test/resources/log4j-strict1.xml
+++ b/log4j-core/src/test/resources/log4j-strict1.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" strict="true" name="XMLConfigTest">
+<Configuration status="OFF" strict="true" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filename">target/test.log</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-style.xml b/log4j-core/src/test/resources/log4j-style.xml
index 9b18b37..2004d72 100644
--- a/log4j-core/src/test/resources/log4j-style.xml
+++ b/log4j-core/src/test/resources/log4j-style.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="StyleTest">
+<Configuration status="OFF" name="StyleTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List">
        <PatternLayout>
diff --git a/log4j-core/src/test/resources/log4j-test1.json b/log4j-core/src/test/resources/log4j-test1.json
index 38a0b22..e7ac524 100644
--- a/log4j-core/src/test/resources/log4j-test1.json
+++ b/log4j-core/src/test/resources/log4j-test1.json
@@ -2,6 +2,7 @@
     "Configuration" : {
         "status": "warn",
         "name": "YAMLConfigTest",
+        "packages": "org.apache.logging.log4j",
 
         "properties" : {
             "property" : {
diff --git a/log4j-core/src/test/resources/log4j-test1.xml b/log4j-core/src/test/resources/log4j-test1.xml
index 3598aec..ef12b91 100644
--- a/log4j-core/src/test/resources/log4j-test1.xml
+++ b/log4j-core/src/test/resources/log4j-test1.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filename">target/test-xml.log</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-test1.yaml b/log4j-core/src/test/resources/log4j-test1.yaml
index d52fdcd..3939e60 100644
--- a/log4j-core/src/test/resources/log4j-test1.yaml
+++ b/log4j-core/src/test/resources/log4j-test1.yaml
@@ -1,6 +1,7 @@
 Configuration:
   status: warn
   name: YAMLConfigTest
+  packages: "org.apache.logging.log4j"
   properties:
     property:
       name: filename
diff --git a/log4j-core/src/test/resources/log4j-test2.xml b/log4j-core/src/test/resources/log4j-test2.xml
index 4cb3225..822b27d 100644
--- a/log4j-core/src/test/resources/log4j-test2.xml
+++ b/log4j-core/src/test/resources/log4j-test2.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest" monitorInterval="1">
+<Configuration status="OFF" name="XMLConfigTest" monitorInterval="1" packages="org.apache.logging.log4j">
   <Appenders>
     <RollingFile name="HostFile" fileName="target/${hostName}.log" filePattern="target/${hostName}-%d{MM-dd-yyyy}-%i.log">
       <PatternLayout>
diff --git a/log4j-core/src/test/resources/log4j-throwable.xml b/log4j-core/src/test/resources/log4j-throwable.xml
index 8189364..3da98d1 100644
--- a/log4j-core/src/test/resources/log4j-throwable.xml
+++ b/log4j-core/src/test/resources/log4j-throwable.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filters">org.junit,org.apache.maven,sun.reflect,java.lang.reflect</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j-throwablefilter.xml b/log4j-core/src/test/resources/log4j-throwablefilter.xml
index be4c476..ce0e881 100644
--- a/log4j-core/src/test/resources/log4j-throwablefilter.xml
+++ b/log4j-core/src/test/resources/log4j-throwablefilter.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration status="OFF" name="XMLConfigTest">
+<Configuration status="OFF" name="XMLConfigTest" packages="org.apache.logging.log4j">
   <Properties>
     <Property name="filters">org.junit,org.apache.maven,sun.reflect,java.lang.reflect</Property>
   </Properties>
diff --git a/log4j-core/src/test/resources/log4j2-calling-class.xml b/log4j-core/src/test/resources/log4j2-calling-class.xml
index 59894ba..9fdcc24 100644
--- a/log4j-core/src/test/resources/log4j2-calling-class.xml
+++ b/log4j-core/src/test/resources/log4j2-calling-class.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration name="CallerInformationTest" status="OFF">
+<Configuration name="CallerInformationTest" status="OFF" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="Class">
       <PatternLayout pattern="%class"/>
diff --git a/log4j-core/src/test/resources/log4j2-config.xml b/log4j-core/src/test/resources/log4j2-config.xml
index e45158c..71a7e43 100644
--- a/log4j-core/src/test/resources/log4j2-config.xml
+++ b/log4j-core/src/test/resources/log4j2-config.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration name="ConfigTest" status="OFF" monitorInterval="5">
+<Configuration name="ConfigTest" status="OFF" monitorInterval="5" packages="org.apache.logging.log4j">
   <Appenders>
     <Console name="STDOUT">
       <PatternLayout pattern="%m%n"/>
diff --git a/log4j-core/src/test/resources/log4j2-mapfilter.xml b/log4j-core/src/test/resources/log4j2-mapfilter.xml
index beddd10..071dbc3 100644
--- a/log4j-core/src/test/resources/log4j2-mapfilter.xml
+++ b/log4j-core/src/test/resources/log4j2-mapfilter.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration name="ConfigTest" status="OFF">
+<Configuration name="ConfigTest" status="OFF" packages="org.apache.logging.log4j">
   <MapFilter onMatch="ACCEPT" onMismatch="NEUTRAL" operator="or">
     <KeyValuePair key="eventId" value="Login"/>
     <KeyValuePair key="eventId" value="Logout"/>
diff --git a/log4j-core/src/test/resources/missingRootLogger.xml b/log4j-core/src/test/resources/missingRootLogger.xml
index 3d4c5c9..1407681 100644
--- a/log4j-core/src/test/resources/missingRootLogger.xml
+++ b/log4j-core/src/test/resources/missingRootLogger.xml
@@ -16,7 +16,7 @@
  limitations under the License.
 
 -->
-<Configuration name="MissingRootTest">
+<Configuration name="MissingRootTest" packages="org.apache.logging.log4j">
   <Appenders>
     <List name="List">
       <PatternLayout>
diff --git a/log4j-jcl/src/test/resources/log4j-test1.xml b/log4j-jcl/src/test/resources/log4j-test1.xml
index ac45198..e3648be 100644
--- a/log4j-jcl/src/test/resources/log4j-test1.xml
+++ b/log4j-jcl/src/test/resources/log4j-test1.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Configuration packages="org.apache.logging.log4j.test" status="debug" name="LoggerTest">
+<Configuration packages="org.apache.logging.log4j,org.apache.logging.log4j.test" status="debug" name="LoggerTest">
   <properties>
     <property name="filename">target/test.log</property>
   </properties>
diff --git a/log4j-slf4j-impl/src/test/resources/log4j-test1.xml b/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
index 439e966..dc7923c 100644
--- a/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
+++ b/log4j-slf4j-impl/src/test/resources/log4j-test1.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<configuration packages="org.apache.logging.log4j.test" status="error" name="LoggerTest">
+<configuration packages="org.apache.logging.log4j,org.apache.logging.log4j.test" status="error" name="LoggerTest">
   <properties>
     <property name="filename">target/test.log</property>
   </properties>
diff --git a/log4j-taglib/src/test/resources/log4j-test1.xml b/log4j-taglib/src/test/resources/log4j-test1.xml
index f8ae21f..03dfb52 100644
--- a/log4j-taglib/src/test/resources/log4j-test1.xml
+++ b/log4j-taglib/src/test/resources/log4j-test1.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<Configuration packages="org.apache.logging.log4j.test" status="warn" name="TaglibLoggerTest">
+<Configuration packages="org.apache.logging.log4j,org.apache.logging.log4j.test" status="warn" name="TaglibLoggerTest">
   <properties>
     <property name="filename">target/test.log</property>
   </properties>
-- 
1.9.2

