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 2017/06/20 02:51:40 UTC

logging-log4j2 git commit: [LOG4J2-1948] Trim levels read from properties file to remove trailing spaces. Closes #75.

Repository: logging-log4j2
Updated Branches:
  refs/heads/master c375ffd12 -> 0cbca29e6


[LOG4J2-1948] Trim levels read from properties file to remove trailing
spaces. Closes #75.

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

Branch: refs/heads/master
Commit: 0cbca29e61863c65541730b1d3c85dff71e80a4c
Parents: c375ffd
Author: Michael Lück <au...@example.com>
Authored: Mon Jun 19 19:51:36 2017 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Mon Jun 19 19:51:36 2017 -0700

----------------------------------------------------------------------
 .../PropertiesConfigurationBuilder.java         |  6 +-
 ...esConfigurationTrailingSpaceOnLevelTest.java | 67 ++++++++++++++++++++
 ...roperties-trailing-space-on-level.properties | 39 ++++++++++++
 src/changes/changes.xml                         |  3 +
 4 files changed, 112 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cbca29e/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 3d24a9b..547d77a 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
@@ -241,7 +241,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
             throw new ConfigurationException("No ref attribute provided for AppenderRef " + key);
         }
         final AppenderRefComponentBuilder appenderRefBuilder = builder.newAppenderRef(ref);
-        final String level = (String) properties.remove("level");
+        final String level = Strings.trimToNull((String) properties.remove("level"));
         if (!Strings.isEmpty(level)) {
             appenderRefBuilder.addAttribute("level", level);
         }
@@ -254,7 +254,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
         if (Strings.isEmpty(name)) {
             throw new ConfigurationException("No name attribute provided for Logger " + key);
         }
-        final String level = (String) properties.remove("level");
+        final String level = Strings.trimToNull((String) properties.remove("level"));
         final String type = (String) properties.remove(CONFIG_TYPE);
         final LoggerComponentBuilder loggerBuilder;
         boolean includeLocation;
@@ -287,7 +287,7 @@ public class PropertiesConfigurationBuilder extends ConfigurationBuilderFactory
     }
 
     private RootLoggerComponentBuilder createRootLogger(final Properties properties) {
-        final String level = (String) properties.remove("level");
+        final String level = Strings.trimToNull((String) properties.remove("level"));
         final String type = (String) properties.remove(CONFIG_TYPE);
         final String location = (String) properties.remove("includeLocation");
         final boolean includeLocation;

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cbca29e/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java
new file mode 100644
index 0000000..743040e
--- /dev/null
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/config/properties/PropertiesConfigurationTrailingSpaceOnLevelTest.java
@@ -0,0 +1,67 @@
+/*
+ * 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.properties;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.core.Appender;
+import org.apache.logging.log4j.core.Filter;
+import org.apache.logging.log4j.core.LifeCycle;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.LoggerConfig;
+import org.apache.logging.log4j.core.filter.ThresholdFilter;
+import org.apache.logging.log4j.junit.LoggerContextRule;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class PropertiesConfigurationTrailingSpaceOnLevelTest {
+
+    @ClassRule
+    public static LoggerContextRule context = new LoggerContextRule(
+            "log4j2-properties-trailing-space-on-level.properties");
+
+    @Test
+    public void testPropertiesConfiguration() {
+        final Configuration config = context.getConfiguration();
+        assertNotNull("No configuration created", config);
+        assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
+        final Map<String, Appender> appenders = config.getAppenders();
+        assertNotNull(appenders);
+        assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
+        final Map<String, LoggerConfig> loggers = config.getLoggers();
+        assertNotNull(loggers);
+        assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
+        final Filter filter = config.getFilter();
+        assertNotNull("No Filter", filter);
+        assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
+        final Logger logger = LogManager.getLogger(getClass());
+
+        assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());
+
+        logger.debug("Welcome to Log4j!");
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cbca29e/log4j-core/src/test/resources/log4j2-properties-trailing-space-on-level.properties
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/resources/log4j2-properties-trailing-space-on-level.properties b/log4j-core/src/test/resources/log4j2-properties-trailing-space-on-level.properties
new file mode 100644
index 0000000..ec18845
--- /dev/null
+++ b/log4j-core/src/test/resources/log4j2-properties-trailing-space-on-level.properties
@@ -0,0 +1,39 @@
+# 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 = ERROR
+dest = err
+
+filter.Threshold.type = ThresholdFilter
+filter.Threshold.level = DEBUG
+
+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.filter.marker.type = MarkerFilter
+appender.Stdout.filter.marker.onMatch = DENY
+appender.Stdout.filter.marker.onMisMatch = NEUTRAL
+appender.Stdout.filter.marker.marker = FLOW
+
+logger.log4j.name = org.apache.logging.log4j
+logger.log4j.appenderRef.console.ref = StdOut
+#added a trailing space to the level on purpose in order to test for correct initialzation of level
+logger.log4j.level = DEBUG 
+logger.log4j.additivity = false
+
+rootLogger.appenderRef.console.ref = StdOut
+rootLogger.level = ERROR
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/0cbca29e/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6a270db..21f9b31 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,9 @@
       <action issue="LOG4J2-1929" dev="ggregory" type="fix" due-to="Borys Sokolov">
         EOFException with FormattedMessage.
       </action>
+      <action issue="LOG4J2-1948" dev="ggregory" type="fix" due-to="Michael Lück">
+        Trim levels read from properties file to remove trailing spaces.
+      </action>
       <action issue="LOG4J2-1442" dev="mikes" type="add">
         Generic HTTP appender.
       </action>