Complete TODO: Remove duplicate code. Note that the common code now uses
Level.valueOf() where the old code used Level.valueOf() in one place and
Level.getLevel() in the other. Level.valueOf() is more bullet proof and
will complain if you pass in a garbage level.

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

Branch: refs/heads/LOG4J-1181
Commit: c58d9282f3cc62101af64cad7f7500a03c23edf0
Parents: d0f81a5
Author: ggregory <[email protected]>
Authored: Fri Oct 30 13:27:43 2015 -0700
Committer: ggregory <[email protected]>
Committed: Fri Oct 30 13:27:43 2015 -0700

----------------------------------------------------------------------
 .../core/config/AbstractConfiguration.java      | 22 +++++++++--------
 .../log4j/core/config/DefaultConfiguration.java | 25 +-------------------
 2 files changed, 13 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c58d9282/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 ba7e6c9..380a37e 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
@@ -500,21 +500,23 @@ public abstract class AbstractConfiguration extends 
AbstractFilterable implement
         setParents();
     }
 
-    private void setToDefault() {
-        // TODO: reduce duplication between this method and 
DefaultConfiguration constructor
+    protected void setToDefault() {
         setName(DefaultConfiguration.DEFAULT_NAME);
         final Layout<? extends Serializable> layout = 
PatternLayout.newBuilder()
-                
.withPattern(DefaultConfiguration.DEFAULT_PATTERN).withConfiguration(this).build();
+                .withPattern(DefaultConfiguration.DEFAULT_PATTERN)
+                .withConfiguration(this)
+                .build();
         final Appender appender = 
ConsoleAppender.createDefaultAppenderForLayout(layout);
         appender.start();
         addAppender(appender);
-        final LoggerConfig loggerConfig = getRootLogger();
-        loggerConfig.addAppender(appender, null, null);
-
-        final String levelName = 
PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL);
-        final Level level = levelName != null && Level.getLevel(levelName) != 
null ? Level.getLevel(levelName)
-                : Level.ERROR;
-        loggerConfig.setLevel(level);
+        final LoggerConfig rootLoggerConfig = getRootLogger();
+        rootLoggerConfig.addAppender(appender, null, null);
+
+        final Level defaultLevel = Level.ERROR;
+        final String levelName = 
PropertiesUtil.getProperties().getStringProperty(DefaultConfiguration.DEFAULT_LEVEL,
+                defaultLevel.name());
+        final Level level = Level.valueOf(levelName);
+        rootLoggerConfig.setLevel(level != null ? level : defaultLevel);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c58d9282/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 925179a..1165ef5 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
@@ -16,15 +16,6 @@
  */
 package org.apache.logging.log4j.core.config;
 
-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.appender.ConsoleAppender;
-import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.util.PropertiesUtil;
-
 /**
  * The default configuration writes all output to the Console using the 
default logging level. You configure default
  * logging level by setting the system property 
"org.apache.logging.log4j.level" to a level name. If you do not
@@ -53,21 +44,7 @@ public class DefaultConfiguration extends 
AbstractConfiguration {
      */
     public DefaultConfiguration() {
         super(ConfigurationSource.NULL_SOURCE);
-        setName(DEFAULT_NAME);
-        final Layout<? extends Serializable> layout = 
PatternLayout.newBuilder()
-            .withPattern(DEFAULT_PATTERN)
-            .withConfiguration(this)
-            .build();
-        final Appender appender = 
ConsoleAppender.createDefaultAppenderForLayout(layout);
-        appender.start();
-        addAppender(appender);
-        final LoggerConfig rootLoggerConfig = getRootLogger();
-        rootLoggerConfig.addAppender(appender, null, null);
-
-        final String levelName = 
PropertiesUtil.getProperties().getStringProperty(DEFAULT_LEVEL);
-        final Level level = levelName != null && Level.valueOf(levelName) != 
null ?
-            Level.valueOf(levelName) : Level.ERROR;
-        rootLoggerConfig.setLevel(level);
+        setToDefault();
     }
 
     @Override

Reply via email to