You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2016/03/06 23:29:52 UTC

[1/4] logging-log4j2 git commit: Fix typo.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master d371d1913 -> 00763d50d


Fix typo.


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

Branch: refs/heads/master
Commit: 275a0389c2a362c558c7dc0ee9ec034c7e27b2c8
Parents: d371d19
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Mar 6 14:35:56 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Mar 6 14:35:56 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/core/util/PropertiesUtilTest.java      | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/275a0389/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
index 5df1a68..62585d7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
@@ -16,14 +16,13 @@
  */
 package org.apache.logging.log4j.core.util;
 
-import org.apache.logging.log4j.util.PropertiesUtil;
-import org.junit.Test;
-
 import java.io.FileInputStream;
 import java.util.Properties;
 
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import org.apache.logging.log4j.util.PropertiesUtil;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
 
 /**
  *
@@ -37,6 +36,6 @@ public class PropertiesUtilTest {
         Properties subset = PropertiesUtil.extractSubset(props, "appender.Stdout.filter.marker");
         assertNotNull("No subset returned", subset);
         assertTrue("Incorrect number of items. Expected 4, actual " + subset.size(), subset.size() == 4);
-        assertTrue("Missing propertu", subset.containsKey("type"));
+        assertTrue("Missing property", subset.containsKey("type"));
     }
 }


[4/4] logging-log4j2 git commit: LOG4J2-1308 - Remove need to pre-specify appender et al. identifiers in property file config format.

Posted by ma...@apache.org.
LOG4J2-1308 - Remove need to pre-specify appender et al. identifiers in property file config format.

Tests and documentation updated to reflect updated format.


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

Branch: refs/heads/master
Commit: 00763d50da2705394ab9cfbb569571a448fddbf2
Parents: c3e6b79
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Mar 6 16:29:45 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Mar 6 16:29:45 2016 -0600

----------------------------------------------------------------------
 .../PropertiesConfigurationBuilder.java         | 88 ++++++++------------
 .../log4j/core/config/ConfigurationTest.java    |  3 +-
 .../src/test/resources/log4j-routing.properties |  9 --
 .../log4j-scriptFile-filters.properties         |  8 --
 .../src/test/resources/log4j-test1.properties   | 58 +++++++++++++
 .../log4j2-properties-root-only.properties      |  6 --
 .../test/resources/log4j2-properties.properties |  9 --
 src/changes/changes.xml                         |  3 +
 src/site/xdoc/manual/configuration.xml.vm       | 20 ++---
 9 files changed, 106 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/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 41802d4..8114a20 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
@@ -17,6 +17,7 @@
 
 package org.apache.logging.log4j.core.config.properties;
 
+import java.util.Map;
 import java.util.Properties;
 
 import org.apache.logging.log4j.Level;
@@ -84,21 +85,18 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
             builder.addProperty(key, propertyPlaceholders.getProperty(key));
         }
 
-        final String scriptProp = (String) rootProperties.remove("scripts");
-        if (scriptProp != null) {
-            final String[] scriptNames = scriptProp.split(",");
-            for (final String scriptName : scriptNames) {
-                final String name = scriptName.trim();
-                final Properties scriptProps = PropertiesUtil.extractSubset(rootProperties, "script." + name);
-                final String type = (String) scriptProps.remove("type");
-                if (type == null) {
-                    throw new ConfigurationException("No type provided for script - must be Script or ScriptFile");
-                }
-                if (type.equalsIgnoreCase("script")) {
-                    builder.add(createScript(scriptProps));
-                } else {
-                    builder.add(createScriptFile(scriptProps));
-                }
+        final Map<String, Properties> scripts = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(rootProperties, "script"));
+        for (final Map.Entry<String, Properties> entry : scripts.entrySet()) {
+            final Properties scriptProps = entry.getValue();
+            final String type = (String) scriptProps.remove("type");
+            if (type == null) {
+                throw new ConfigurationException("No type provided for script - must be Script or ScriptFile");
+            }
+            if (type.equalsIgnoreCase("script")) {
+                builder.add(createScript(scriptProps));
+            } else {
+                builder.add(createScriptFile(scriptProps));
             }
         }
 
@@ -109,32 +107,24 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
             }
         }
 
-        final String filterProp = (String) rootProperties.remove("filters");
-        if (filterProp != null) {
-            final String[] filterNames = filterProp.split(",");
-            for (final String filterName : filterNames) {
-                final String name = filterName.trim();
-                builder.add(createFilter(name, PropertiesUtil.extractSubset(rootProperties, "filter." + name)));
-            }
+        final Map<String, Properties> filters = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(rootProperties, "filter"));
+        for (final Map.Entry<String, Properties> entry : filters.entrySet()) {
+            builder.add(createFilter(entry.getKey().trim(), entry.getValue()));
         }
 
-        final String appenderProp = (String) rootProperties.remove("appenders");
-        if (appenderProp != null) {
-            final String[] appenderNames = appenderProp.split(",");
-            for (final String appenderName : appenderNames) {
-                final String name = appenderName.trim();
-                builder.add(createAppender(name, PropertiesUtil.extractSubset(rootProperties, "appender." + name)));
-            }
+        final Map<String, Properties> appenders = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(rootProperties, "appender"));
+        for (final Map.Entry<String, Properties> entry : appenders.entrySet()) {
+            builder.add(createAppender(entry.getKey().trim(), entry.getValue()));
         }
 
-        final String loggerProp = (String) rootProperties.remove("loggers");
-        if (loggerProp != null) {
-            final String[] loggerNames = loggerProp.split(",");
-            for (final String loggerName : loggerNames) {
-                final String name = loggerName.trim();
-                if (!name.equals(LoggerConfig.ROOT)) {
-                    builder.add(createLogger(name, PropertiesUtil.extractSubset(rootProperties, "logger." + name)));
-                }
+        final Map<String, Properties> loggers = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(rootProperties, "logger"));
+        for (final Map.Entry<String, Properties> entry : loggers.entrySet()) {
+            final String name = entry.getKey().trim();
+            if (!name.equals(LoggerConfig.ROOT)) {
+                builder.add(createLogger(name, entry.getValue()));
             }
         }
 
@@ -288,28 +278,20 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
 
     private <B extends FilterableComponentBuilder<? extends ComponentBuilder<?>>> B addFiltersToComponent(
         final B componentBuilder, final Properties properties) {
-        final String filters = (String) properties.remove("filters");
-        if (filters != null) {
-            final String[] filterNames = filters.split(",");
-            for (final String name : filterNames) {
-                final String filterName = name.trim();
-                final Properties filterProps = PropertiesUtil.extractSubset(properties, "filter." + filterName);
-                componentBuilder.add(createFilter(filterName, filterProps));
-            }
+        final Map<String, Properties> filters = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(properties, "filter"));
+        for (final Map.Entry<String, Properties> entry : filters.entrySet()) {
+            componentBuilder.add(createFilter(entry.getKey().trim(), entry.getValue()));
         }
         return componentBuilder;
     }
 
     private <B extends LoggableComponentBuilder<? extends ComponentBuilder<?>>> B addLoggersToComponent(
         final B loggerBuilder, final Properties properties) {
-        final String appenderRefs = (String) properties.remove("appenderRefs");
-        if (appenderRefs != null) {
-            final String[] refNames = appenderRefs.split(",");
-            for (final String refName : refNames) {
-                final String appenderRef = refName.trim();
-                final Properties refProps = PropertiesUtil.extractSubset(properties, "appenderRef." + appenderRef);
-                loggerBuilder.add(createAppenderRef(appenderRef, refProps));
-            }
+        final Map<String, Properties> appenderRefs = PropertiesUtil.partitionOnCommonPrefixes(
+            PropertiesUtil.extractSubset(properties, "appenderRef"));
+        for (final Map.Entry<String, Properties> entry : appenderRefs.entrySet()) {
+            loggerBuilder.add(createAppenderRef(entry.getKey().trim(), entry.getValue()));
         }
         return loggerBuilder;
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/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 05afe80..4cfe7c3 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
@@ -81,7 +81,8 @@ public class ConfigurationTest {
                 new Object[][]{
                         {"classpath:log4j-test1.xml", "target/test-xml.log"},
                         {"classpath:log4j-test1.json", "target/test-json.log"},
-                        {"classpath:log4j-test1.yaml", "target/test-yaml.log"}
+                        {"classpath:log4j-test1.yaml", "target/test-yaml.log"},
+                        {"classpath:log4j-test1.properties", "target/test-properties.log"}
                 }
         );
     }

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/log4j-core/src/test/resources/log4j-routing.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-routing.properties b/log4j-core/src/test/resources/log4j-routing.properties
index dc68cdc..c365e35 100644
--- a/log4j-core/src/test/resources/log4j-routing.properties
+++ b/log4j-core/src/test/resources/log4j-routing.properties
@@ -18,13 +18,9 @@ name = RoutingTest
 
 property.filename = target/routing1/routingtestProps-$${sd:type}.log
 
-filters = threshold
-
 filter.threshold.type = ThresholdFilter
 filter.threshold.level = debug
 
-appenders = console, routing, list
-
 appender.console.type = Console
 appender.console.name = STDOUT
 appender.console.layout.type = PatternLayout
@@ -52,18 +48,13 @@ appender.routing.routes.route3.key = Service
 
 appender.list.type = List
 appender.list.name = List
-appender.list.filters = threshold
 appender.list.filter.threshold.type = ThresholdFilter
 appender.list.filter.threshold.level = debug
 
-loggers = event
-
 logger.event.name = EventLogger
 logger.event.level = info
 logger.event.additivity = false
-logger.event.appenderRefs = routing
 logger.event.appenderRef.routing.ref = Routing
 
 rootLogger.level = error
-rootLogger.appenderRefs = stdout
 rootLogger.appenderRef.stdout.ref = STDOUT

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/log4j-core/src/test/resources/log4j-scriptFile-filters.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-scriptFile-filters.properties b/log4j-core/src/test/resources/log4j-scriptFile-filters.properties
index ac1874b..0daab51 100644
--- a/log4j-core/src/test/resources/log4j-scriptFile-filters.properties
+++ b/log4j-core/src/test/resources/log4j-scriptFile-filters.properties
@@ -16,7 +16,6 @@
 status = error
 name = ScriptConfigTest
 
-scripts = javascript, groovy
 script.javascript.type = ScriptFile
 script.javascript.name = filter.js
 script.javascript.language = JavaScript
@@ -27,19 +26,15 @@ script.groovy.name = filter.groovy
 script.groovy.path = src/test/resources/scripts/filter.groovy
 script.groovy.charset = UTF-8
 
-appenders = list
 appender.list.type = List
 appender.list.name = List
 appender.list.layout.type = PatternLayout
 appender.list.layout.pattern = [%-5level] %c{1.} %msg%n
 
-loggers = javascriptFilter, groovyFilter
 logger.javascriptFilter.name = TestJavaScriptFilter
 logger.javascriptFilter.level = trace
 logger.javascriptFilter.additivity = false
-logger.javascriptFilter.appenderRefs = list
 logger.javascriptFilter.appenderRef.list.ref = List
-logger.javascriptFilter.filters = script
 logger.javascriptFilter.filter.script.type = ScriptFilter
 logger.javascriptFilter.filter.script.onMatch = ACCEPT
 logger.javascriptFilter.filter.script.onMisMatch = DENY
@@ -49,9 +44,7 @@ logger.javascriptFilter.filter.script.ref.ref = filter.js
 logger.groovyFilter.name = TestGroovyFilter
 logger.groovyFilter.level = trace
 logger.groovyFilter.additivity = false
-logger.groovyFilter.appenderRefs = list
 logger.groovyFilter.appenderRef.list.ref = List
-logger.groovyFilter.filters = script
 logger.groovyFilter.filter.script.type = ScriptFilter
 logger.groovyFilter.filter.script.onMatch = ACCEPT
 logger.groovyFilter.filter.script.onMisMatch = DENY
@@ -59,5 +52,4 @@ logger.groovyFilter.filter.script.ref.type = ScriptRef
 logger.groovyFilter.filter.script.ref.ref = filter.groovy
 
 rootLogger.level = trace
-rootLogger.appenderRefs = list
 rootLogger.appenderRef.list.ref = List

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/log4j-core/src/test/resources/log4j-test1.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j-test1.properties b/log4j-core/src/test/resources/log4j-test1.properties
new file mode 100644
index 0000000..3ded230
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j-test1.properties
@@ -0,0 +1,58 @@
+#
+# 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.
+#
+
+status = off
+name = PropertiesConfigTest
+
+property.filename = target/test-properties.log
+
+filter.threshold.type = ThresholdFilter
+filter.threshold.level = debug
+
+appender.console.name = STDOUT
+appender.console.type = Console
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %m%n
+
+appender.file.name = File
+appender.file.type = File
+appender.file.fileName = ${filename}
+appender.file.bufferedIO = false
+appender.file.layout.type = PatternLayout
+appender.file.layout.pattern = %d %p %C{1.} [%t] %m%n
+
+appender.list.name = List
+appender.list.type = List
+appender.list.filter.threshold.type = ThresholdFilter
+appender.list.filter.threshold.level = error
+
+logger.test1.name = org.apache.logging.log4j.test1
+logger.test1.level = debug
+logger.test1.additivity = false
+logger.test1.filter.mdc.type = ThreadContextMapFilter
+logger.test1.filter.mdc.pair.type = KeyValuePair
+logger.test1.filter.mdc.pair.key = test
+logger.test1.filter.mdc.pair.value = 123
+logger.test1.appenderRef.console.ref = STDOUT
+
+logger.test2.name = org.apache.logging.log4j.test2
+logger.test2.level = debug
+logger.test2.additivity = false
+logger.test2.appenderRef.file.ref = File
+
+rootLogger.level = error
+rootLogger.appenderRef.console.ref = STDOUT

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/log4j-core/src/test/resources/log4j2-properties-root-only.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j2-properties-root-only.properties b/log4j-core/src/test/resources/log4j2-properties-root-only.properties
index 7587606..265686a 100644
--- a/log4j-core/src/test/resources/log4j2-properties-root-only.properties
+++ b/log4j-core/src/test/resources/log4j2-properties-root-only.properties
@@ -15,24 +15,18 @@
 
 status = ERROR
 
-filters = Threshold
-
 filter.Threshold.type = ThresholdFilter
 filter.Threshold.level = DEBUG
 
-appenders = Stdout
-
 appender.Stdout.type = Console
 appender.Stdout.name = StdOut
 appender.Stdout.target = SYSTEM_OUT
 appender.Stdout.layout.type = PatternLayout
 appender.Stdout.layout.pattern = %d [%t] %-5level: %msg%n%throwable
-appender.Stdout.filters = marker
 appender.Stdout.filter.marker.type = MarkerFilter
 appender.Stdout.filter.marker.onMatch = DENY
 appender.Stdout.filter.marker.onMisMatch = NEUTRAL
 appender.Stdout.filter.marker.marker = FLOW
 
-rootLogger.appenderRefs = console
 rootLogger.appenderRef.console.ref = StdOut
 rootLogger.level = ERROR

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/log4j-core/src/test/resources/log4j2-properties.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j2-properties.properties b/log4j-core/src/test/resources/log4j2-properties.properties
index 716a9ca..c446d82 100644
--- a/log4j-core/src/test/resources/log4j2-properties.properties
+++ b/log4j-core/src/test/resources/log4j2-properties.properties
@@ -15,32 +15,23 @@
 
 status = ERROR
 
-filters = Threshold
-
 filter.Threshold.type = ThresholdFilter
 filter.Threshold.level = DEBUG
 
-appenders = Stdout
-
 appender.Stdout.type = Console
 appender.Stdout.name = StdOut
 appender.Stdout.target = SYSTEM_OUT
 appender.Stdout.layout.type = PatternLayout
 appender.Stdout.layout.pattern = %d [%t] %-5level: %msg%n%throwable
-appender.Stdout.filters = marker
 appender.Stdout.filter.marker.type = MarkerFilter
 appender.Stdout.filter.marker.onMatch = DENY
 appender.Stdout.filter.marker.onMisMatch = NEUTRAL
 appender.Stdout.filter.marker.marker = FLOW
 
-loggers = log4j
-
 logger.log4j.name = org.apache.logging.log4j
-logger.log4j.appenderRefs = console
 logger.log4j.appenderRef.console.ref = StdOut
 logger.log4j.level = DEBUG
 logger.log4j.additivity = false
 
-rootLogger.appenderRefs = console
 rootLogger.appenderRef.console.ref = StdOut
 rootLogger.level = ERROR

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 434c3ab..f64dc5b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -193,6 +193,9 @@
       <action issue="LOG4J2-1217" dev="mattsicker" type="add" due-to="Thies Wellpott">
         PatternLayout option to limit length of text.
       </action>
+      <action issue="LOG4J2-1308" dev="mattsicker" type="update">
+        Remove need to pre-specify appender et al. identifiers in property file config format.
+      </action>
     </release>
     <release version="2.5" date="2015-12-06" description="GA Release 2.5">
       <action issue="LOG4J2-324" dev="rpopma" type="fix">

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/00763d50/src/site/xdoc/manual/configuration.xml.vm
----------------------------------------------------------------------
diff --git a/src/site/xdoc/manual/configuration.xml.vm b/src/site/xdoc/manual/configuration.xml.vm
index 18367eb..4bf5247 100644
--- a/src/site/xdoc/manual/configuration.xml.vm
+++ b/src/site/xdoc/manual/configuration.xml.vm
@@ -818,7 +818,8 @@ public class Bar {
               configurations define the configuration in terms of plugins and attributes to the plugins.
             </p>
             <p>
-              The properties configuration requires that you list the identifiers of the appenders, filters and loggers,
+              Prior to version 2.6,
+              the properties configuration requires that you list the identifiers of the appenders, filters and loggers,
               in a comma separated list in properties with those names. Each of those components will then be expected
               to be defined in sets of properties that begin with <i>component.identifier</i>. The identifier does not
               have to match the name of the component being defined but must uniquely identify all the attributes and
@@ -826,6 +827,10 @@ public class Bar {
               specified that identifies the component's Plugin type.
             </p>
             <p>
+              As of version 2.6, this list of identifiers is no longer required as names are inferred upon first usage.
+              The list of identifiers used in a 2.4/2.5 format will be safely ignored in 2.6+.
+            </p>
+            <p>
               Unlike the base components, when creating subcomponents you cannot specify an element containing a list of
               identifiers. Instead, you must define the wrapper element with its type as is shown in the policies
               definition in the rolling file appender below. You then define each of the subcomponents below that
@@ -842,13 +847,9 @@ name = PropertiesConfig
 
 property.filename = target/rolling/rollingtest.log
 
-filters = threshold
-
 filter.threshold.type = ThresholdFilter
 filter.threshold.level = debug
 
-appenders = console, rolling, list
-
 appender.console.type = Console
 appender.console.name = STDOUT
 appender.console.layout.type = PatternLayout
@@ -871,20 +872,15 @@ appender.rolling.strategy.max = 5
 
 appender.list.type = List
 appender.list.name = List
-appender.list.filters = threshold
 appender.list.filter.threshold.type = ThresholdFilter
 appender.list.filter.threshold.level = error
 
-loggers = rolling
-
 logger.rolling.name = com.example.my.app
 logger.rolling.level = debug
 logger.rolling.additivity = false
-logger.rolling.appenderRefs = rolling
 logger.rolling.appenderRef.rolling.ref = RollingFile
 
 rootLogger.level = info
-rootLogger.appenderRefs = stdout
 rootLogger.appenderRef.stdout.ref = STDOUT
           </pre>
         </subsection>
@@ -1474,14 +1470,14 @@ StatusLogger.getLogger().registerListener(listener);
           named file to be used during the test.
         </p>
           <p>
-            A third approach, also used extensively by Log4j 2, is to use the <code>InitialLoggerContext</code>
+            A third approach, also used extensively by Log4j 2, is to use the <code>LoggerContextRule</code>
             JUnit test rule which provides additional convenience methods for testing. This requires adding the
             <code>log4j-core</code> <code>test-jar</code> dependency to your test scope dependencies. For example:
           </p>
           <pre class="prettyprint linenums"><![CDATA[
 public class AwesomeTest {
     @Rule
-    public InitialLoggerContext init = new InitialLoggerContext("MyTestConfig.xml");
+    public LoggerContextRule init = new LoggerContextRule("MyTestConfig.xml");
 
     @Test
     public void testSomeAwesomeFeature() {


[3/4] logging-log4j2 git commit: Add properties util partition method and consolidate tests.

Posted by ma...@apache.org.
Add properties util partition method and consolidate tests.


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

Branch: refs/heads/master
Commit: c3e6b79e0a963a4b34e13c7a4d57addc7e23b31e
Parents: a528d78
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Mar 6 16:24:59 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Mar 6 16:24:59 2016 -0600

----------------------------------------------------------------------
 .../logging/log4j/util/PropertiesUtil.java      | 22 +++++++
 .../logging/log4j/util/PropertiesUtilTest.java  | 65 ++++++++++++++++++++
 .../resources/PropertiesUtilTest.properties     | 29 +++++++++
 .../log4j/core/util/PropertiesUtilTest.java     | 40 ------------
 4 files changed, 116 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3e6b79e/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
index a09251f..1bc4e43 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/util/PropertiesUtil.java
@@ -21,7 +21,9 @@ import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * <em>Consider this class private.</em>
@@ -255,6 +257,26 @@ public final class PropertiesUtil {
     }
 
     /**
+     * Partitions a properties map based on common key prefixes up to the first period.
+     *
+     * @param properties properties to partition
+     * @return the partitioned properties where each key is the common prefix (minus the period) and the values are
+     * new property maps without the prefix and period in the key
+     * @since 2.6
+     */
+    public static Map<String, Properties> partitionOnCommonPrefixes(final Properties properties) {
+        final Map<String, Properties> parts = new ConcurrentHashMap<>();
+        for (final String key : properties.stringPropertyNames()) {
+            final String prefix = key.substring(0, key.indexOf('.'));
+            if (!parts.containsKey(prefix)) {
+                parts.put(prefix, new Properties());
+            }
+            parts.get(prefix).setProperty(key.substring(key.indexOf('.') + 1), properties.getProperty(key));
+        }
+        return parts;
+    }
+
+    /**
      * Returns true if system properties tell us we are running on Windows.
      * @return true if system properties tell us we are running on Windows.
      */

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3e6b79e/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
new file mode 100644
index 0000000..131e87b
--- /dev/null
+++ b/log4j-api/src/test/java/org/apache/logging/log4j/util/PropertiesUtilTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.util;
+
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+/**
+ *
+ */
+public class PropertiesUtilTest {
+
+    private final Properties properties = new Properties();
+
+    @Before
+    public void setUp() throws Exception {
+        properties.load(ClassLoader.getSystemResourceAsStream("PropertiesUtilTest.properties"));
+    }
+
+    @Test
+    public void testExtractSubset() throws Exception {
+        assertHasAllProperties(PropertiesUtil.extractSubset(properties, "a"));
+        assertHasAllProperties(PropertiesUtil.extractSubset(properties, "b."));
+        assertHasAllProperties(PropertiesUtil.extractSubset(properties, "c.1"));
+        assertHasAllProperties(PropertiesUtil.extractSubset(properties, "dd"));
+        assertEquals(0, properties.size());
+    }
+
+    @Test
+    public void testPartitionOnCommonPrefix() throws Exception {
+        final Map<String, Properties> parts = PropertiesUtil.partitionOnCommonPrefixes(properties);
+        assertEquals(4, parts.size());
+        assertHasAllProperties(parts.get("a"));
+        assertHasAllProperties(parts.get("b"));
+        assertHasAllProperties(PropertiesUtil.partitionOnCommonPrefixes(parts.get("c")).get("1"));
+        assertHasAllProperties(parts.get("dd"));
+    }
+
+    private static void assertHasAllProperties(final Properties properties) {
+        assertNotNull(properties);
+        assertEquals("1", properties.getProperty("1"));
+        assertEquals("2", properties.getProperty("2"));
+        assertEquals("3", properties.getProperty("3"));
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3e6b79e/log4j-api/src/test/resources/PropertiesUtilTest.properties
----------------------------------------------------------------------
diff --git a/log4j-api/src/test/resources/PropertiesUtilTest.properties b/log4j-api/src/test/resources/PropertiesUtilTest.properties
new file mode 100644
index 0000000..46e67d5
--- /dev/null
+++ b/log4j-api/src/test/resources/PropertiesUtilTest.properties
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+a.1 = 1
+a.2 = 2
+a.3 = 3
+b.1 = 1
+b.2 = 2
+b.3 = 3
+c.1.1 = 1
+c.1.2 = 2
+c.1.3 = 3
+dd.1 = 1
+dd.2 = 2
+dd.3 = 3

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c3e6b79e/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
deleted file mode 100644
index b2ededc..0000000
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.util;
-
-import java.util.Properties;
-
-import org.apache.logging.log4j.util.PropertiesUtil;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-/**
- *
- */
-public class PropertiesUtilTest {
-
-    @Test
-    public void testSubset() throws Exception {
-        Properties props = new Properties();
-        props.load(ClassLoader.getSystemResourceAsStream("log4j2-properties.properties"));
-        Properties subset = PropertiesUtil.extractSubset(props, "appender.Stdout.filter.marker");
-        assertNotNull("No subset returned", subset);
-        assertTrue("Incorrect number of items. Expected 4, actual " + subset.size(), subset.size() == 4);
-        assertTrue("Missing property", subset.containsKey("type"));
-    }
-}


[2/4] logging-log4j2 git commit: Use class loader resource in test.

Posted by ma...@apache.org.
Use class loader resource in test.


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

Branch: refs/heads/master
Commit: a528d789767b0a90ceeaa8ae54dbba198b0513e7
Parents: 275a038
Author: Matt Sicker <bo...@gmail.com>
Authored: Sun Mar 6 14:39:33 2016 -0600
Committer: Matt Sicker <bo...@gmail.com>
Committed: Sun Mar 6 14:39:33 2016 -0600

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/util/PropertiesUtilTest.java    | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a528d789/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
index 62585d7..b2ededc 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/util/PropertiesUtilTest.java
@@ -16,7 +16,6 @@
  */
 package org.apache.logging.log4j.core.util;
 
-import java.io.FileInputStream;
 import java.util.Properties;
 
 import org.apache.logging.log4j.util.PropertiesUtil;
@@ -32,7 +31,7 @@ public class PropertiesUtilTest {
     @Test
     public void testSubset() throws Exception {
         Properties props = new Properties();
-        props.load(new FileInputStream("target/test-classes/log4j2-properties.properties"));
+        props.load(ClassLoader.getSystemResourceAsStream("log4j2-properties.properties"));
         Properties subset = PropertiesUtil.extractSubset(props, "appender.Stdout.filter.marker");
         assertNotNull("No subset returned", subset);
         assertTrue("Incorrect number of items. Expected 4, actual " + subset.size(), subset.size() == 4);