Repository: logging-log4j2
Updated Branches:
  refs/heads/master e2a197f3e -> efa163b9a


Set the class name and display name when executing a rule. This is to
let configuration files to be more flexible in a large test suite. For
example: I want to use one log file per test class.

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

Branch: refs/heads/master
Commit: efa163b9a33a8c9bbe948e4de629fdbafccd0783
Parents: e2a197f
Author: ggregory <[email protected]>
Authored: Fri Oct 23 18:58:22 2015 -0700
Committer: ggregory <[email protected]>
Committed: Fri Oct 23 18:58:22 2015 -0700

----------------------------------------------------------------------
 .../java/org/apache/logging/log4j/junit/LoggerContextRule.java | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/efa163b9/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
 
b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
index 1915a2f..5bbda4f 100644
--- 
a/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
+++ 
b/log4j-core/src/test/java/org/apache/logging/log4j/junit/LoggerContextRule.java
@@ -40,6 +40,8 @@ import static org.junit.Assert.*;
  */
 public class LoggerContextRule implements TestRule {
 
+    private static final String SYS_PROP_KEY_DISPLAY_NAME = 
"org.apache.logging.log4j.junit.LoggerContextRule#DisplayName";
+    private static final String SYS_PROP_KEY_CLASS_NAME = 
"org.apache.logging.log4j.junit.LoggerContextRule#ClassName";
     private final String configLocation;
     private final Class<? extends ContextSelector> contextSelectorClass;
 
@@ -81,6 +83,8 @@ public class LoggerContextRule implements TestRule {
                 if (contextSelectorClass != null) {
                     System.setProperty(Constants.LOG4J_CONTEXT_SELECTOR, 
contextSelectorClass.getName());
                 }
+                System.setProperty(SYS_PROP_KEY_CLASS_NAME, 
description.getClassName());
+                System.setProperty(SYS_PROP_KEY_DISPLAY_NAME, 
description.getDisplayName());
                 context = Configurator.initialize(
                     description.getDisplayName(),
                     description.getTestClass().getClassLoader(),
@@ -92,6 +96,8 @@ public class LoggerContextRule implements TestRule {
                     Configurator.shutdown(context);
                     StatusLogger.getLogger().reset();
                     System.clearProperty(Constants.LOG4J_CONTEXT_SELECTOR);
+                    System.clearProperty(SYS_PROP_KEY_CLASS_NAME);
+                    System.clearProperty(SYS_PROP_KEY_DISPLAY_NAME);
                 }
             }
         };

Reply via email to