Repository: logging-log4j2
Updated Branches:
  refs/heads/master 88e4497ea -> 180b38c96


Refactor some common code.

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

Branch: refs/heads/master
Commit: 180b38c9695273acd61f9a5d42b8ab5be9924361
Parents: 88e4497
Author: Gary Gregory <[email protected]>
Authored: Fri Sep 23 18:32:11 2016 -0700
Committer: Gary Gregory <[email protected]>
Committed: Fri Sep 23 18:32:11 2016 -0700

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java  | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/180b38c9/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 5462697..ca13bab 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
@@ -61,6 +61,7 @@ import org.apache.velocity.runtime.directive.Foreach;
  */
 public class Log4j1ConfigurationParser {
 
+    private static final String COMMA_DELIMITED_RE = "\\s*,\\s*";
     private static final String ROOTLOGGER = "rootLogger";
     private static final String ROOTCATEGORY = "rootCategory";
     private static final String TRUE = "true";
@@ -358,8 +359,8 @@ public class Log4j1ConfigurationParser {
         if (rootLoggerValue == null) {
             return new String[0];
         }
-        final String[] rootLoggerParts = rootLoggerValue.split("\\s*,\\s*");
-        final Level rootLoggerLevel = rootLoggerParts.length > 0 ? 
Level.valueOf(rootLoggerParts[0]) : Level.ERROR;
+        final String[] rootLoggerParts = 
rootLoggerValue.split(COMMA_DELIMITED_RE);
+        final Level rootLoggerLevel = getLevel(rootLoggerParts, Level.ERROR);
         final String[] sortedAppenderNames = 
Arrays.copyOfRange(rootLoggerParts, 1, rootLoggerParts.length);
         Arrays.sort(sortedAppenderNames);
         final RootLoggerComponentBuilder loggerBuilder = 
builder.newRootLogger(rootLoggerLevel);
@@ -370,6 +371,10 @@ public class Log4j1ConfigurationParser {
         return sortedAppenderNames;
     }
 
+    private Level getLevel(final String[] loggerParts, final Level 
defaultLevel) {
+        return loggerParts.length > 0 ? Level.valueOf(loggerParts[0]) : 
defaultLevel;
+    }
+
     private void buildLoggers(final String prefix) {
         final int preLength = prefix.length();
         for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
@@ -382,12 +387,12 @@ public class Log4j1ConfigurationParser {
                     if (value != null) {
                         // a Level may be followed by a list of Appender refs.
                         final String valueStr = value.toString();
-                        final String[] split = valueStr.split("\\s*,\\s*");
-                        final String levelStr = split.length > 0 ? split[0] : 
null;
-                        if (levelStr == null) {
-                            warn("Level is missing: " + entry);
+                        final String[] split = 
valueStr.split(COMMA_DELIMITED_RE);
+                        final Level level = getLevel(split, null);
+                        if (level == null) {
+                            warn("Level is missing for entry " + entry);
                         } else {
-                            final LoggerComponentBuilder newLogger = 
builder.newLogger(name, Level.valueOf(levelStr));
+                            final LoggerComponentBuilder newLogger = 
builder.newLogger(name, level);
                             if (split.length > 1) {
                                 // Add Appenders to this logger
                                 for (int i = 1; i < split.length; i++) {

Reply via email to