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 2016/09/24 01:10:31 UTC

logging-log4j2 git commit: Allow for a logger to be defined as "Level, AppenderRef, AppenderRef, ..."

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 2fc6784f7 -> a6cf48e93


Allow for a logger to be defined as "Level, AppenderRef, AppenderRef,
..."

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

Branch: refs/heads/master
Commit: a6cf48e934a6de94df5c302db6b55d29027c3cc8
Parents: 2fc6784
Author: Gary Gregory <gg...@apache.org>
Authored: Fri Sep 23 18:10:28 2016 -0700
Committer: Gary Gregory <gg...@apache.org>
Committed: Fri Sep 23 18:10:28 2016 -0700

----------------------------------------------------------------------
 .../log4j/config/Log4j1ConfigurationParser.java | 21 +++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/a6cf48e9/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 da9bc8f..b346fac 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
@@ -23,6 +23,8 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 
+import javax.swing.text.StyledEditorKit.ForegroundAction;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.appender.ConsoleAppender;
 import org.apache.logging.log4j.core.appender.FileAppender;
@@ -34,10 +36,12 @@ import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
 import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
 import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
+import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder;
 import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
 import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
 import org.apache.logging.log4j.status.StatusLogger;
+import org.apache.velocity.runtime.directive.Foreach;
 
 /**
  * Experimental parser for Log4j 1.2 properties configuration files.
@@ -376,7 +380,22 @@ public class Log4j1ConfigurationParser {
                     final String name = key.substring(preLength);
                     final Object value = entry.getValue();
                     if (value != null) {
-                        builder.add(builder.newLogger(name, Level.valueOf(value.toString())));
+                        // 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);
+                        } else {
+                            final LoggerComponentBuilder newLogger = builder.newLogger(name, Level.valueOf(levelStr));
+                            if (split.length > 1) {
+                                // Add Appenders to this logger
+                                for (int i = 1; i < split.length; i++) {
+                                    newLogger.add(builder.newAppenderRef(split[i]));
+                                }
+                            }
+                            builder.add(newLogger);
+                        }
                     }
                 }
             }