Repository: logging-log4j2
Updated Branches:
  refs/heads/LOG4J2-1597 79d9e1137 -> c5ee9dc34


Overwrite the name in the Node's attribute map.

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

Branch: refs/heads/LOG4J2-1597
Commit: c5ee9dc34317a4cf832db977a20049f76f9405a1
Parents: 79d9e11
Author: Gary Gregory <ggreg...@apache.org>
Authored: Sun Sep 18 22:31:55 2016 -0700
Committer: Gary Gregory <ggreg...@apache.org>
Committed: Sun Sep 18 22:31:55 2016 -0700

----------------------------------------------------------------------
 .../org/apache/logging/log4j/core/appender/AppenderSet.java | 3 ++-
 .../apache/logging/log4j/core/appender/ScriptSelector.java  | 4 +---
 .../log4j/core/appender/ScriptSelectorAppenderTest.java     | 9 +++++++--
 3 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5ee9dc3/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java
index 4403ab4..472e456 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/AppenderSet.java
@@ -108,12 +108,13 @@ public class AppenderSet {
         this.nodeMap = appenders;
     }
 
-    public Appender createAppender(final String appenderName) {
+    public Appender createAppender(final String appenderName, String 
actualName) {
         final Node node = nodeMap.get(appenderName);
         if (node == null) {
             LOGGER.error("No node named {} in {}", appenderName, this);
             return null;
         }
+        node.getAttributes().put("name", actualName);
         if (node.getType().getElementName().equals("appender")) {
             final Node appNode = new Node(node);
             configuration.createConfiguration(appNode, null);

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5ee9dc3/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptSelector.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptSelector.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptSelector.java
index 028f5b7..0088abf 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptSelector.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/appender/ScriptSelector.java
@@ -78,9 +78,7 @@ public class ScriptSelector extends AbstractAppender {
             final Bindings bindings = scriptManager.createBindings(script);
             final Object object = scriptManager.execute(script.getName(), 
bindings);
             final String appenderName = Objects.toString(object, null);
-            final Appender appender = appenderSet.createAppender(appenderName);
-            // This feels like a hack and it does not work:
-            configuration.getAppenders().put(name, appender);
+            final Appender appender = appenderSet.createAppender(appenderName, 
name);
             return appender;
         }
 

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c5ee9dc3/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ScriptSelectorAppenderTest.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ScriptSelectorAppenderTest.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ScriptSelectorAppenderTest.java
index 3a037c0..e1c8a14 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ScriptSelectorAppenderTest.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/ScriptSelectorAppenderTest.java
@@ -56,7 +56,7 @@ public class ScriptSelectorAppenderTest {
     }
 
     private ListAppender getListAppender() {
-        return loggerContextRule.getListAppender("List2");
+        return loggerContextRule.getListAppender("SelectIt");
     }
 
     private void logAndCheck() {
@@ -74,10 +74,15 @@ public class ScriptSelectorAppenderTest {
     }
 
     @Test(expected = AssertionError.class)
-    public void testAppenderAbsence() {
+    public void testAppender1Absence() {
         loggerContextRule.getListAppender("List1");
     }
 
+    @Test(expected = AssertionError.class)
+    public void testAppender2Absence() {
+        loggerContextRule.getListAppender("List2");
+    }
+
     @Test
     public void testAppenderPresence() {
         getListAppender();

Reply via email to