logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject svn commit: r553711 - in /logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul: AssertionHandler.java JULAppenderTest.java
Date Fri, 06 Jul 2007 03:13:31 GMT
Author: psmith
Date: Thu Jul  5 20:13:30 2007
New Revision: 553711

URL: http://svn.apache.org/viewvc?view=rev&rev=553711
Log:
Finally tracked down the weird mvn test problem.

Turns out that under 'mvn test' the log4j Logging system is still configured
in between tests unless one specifically resets the configuration in the setUp().

This makes perfect sense. What doesn't make sense is why all the tests pass in the Eclipse
junit runner.  I suspect because it uses private classloaders for each test in isolation.



Modified:
    logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/AssertionHandler.java
    logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULAppenderTest.java

Modified: logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/AssertionHandler.java
URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/AssertionHandler.java?view=diff&rev=553711&r1=553710&r2=553711
==============================================================================
--- logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/AssertionHandler.java
(original)
+++ logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/AssertionHandler.java
Thu Jul  5 20:13:30 2007
@@ -58,7 +58,9 @@
     public void publish(LogRecord record) {
         lastObservedLogRecord = record;
         activated = true;
-        passed = expectedMessage.equals(record.getMessage());
+        if(expectedMessage != null) {
+            passed = expectedMessage.equals(record.getMessage());
+        }
         if(expectedLevel != null) {
             passed = passed && (expectedLevel.intValue() == record.getLevel().intValue());
         }
@@ -87,7 +89,7 @@
             return "{no LogRecord seen}";
         }
         StringBuffer buf = new StringBuffer();
-        buf.append(record.getLoggerName()).append(",").append(record.getMessage());
+        buf.append(record.getLoggerName()).append(",").append(record.getMessage()).append("level:").append(record.getLevel());
         return buf.toString();
     }
 

Modified: logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULAppenderTest.java
URL: http://svn.apache.org/viewvc/logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULAppenderTest.java?view=diff&rev=553711&r1=553710&r2=553711
==============================================================================
--- logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULAppenderTest.java
(original)
+++ logging/sandbox/jul-to-log4j-bridge/src/test/java/org/apache/log4j/jul/JULAppenderTest.java
Thu Jul  5 20:13:30 2007
@@ -18,22 +18,24 @@
 package org.apache.log4j.jul;
 
 
+import junit.framework.TestCase;
+
 import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
 import org.apache.logging.julbridge.JULLog4jBridge;
 
-import junit.framework.*;
-
 /** JulAppender test case
  *
  * @author Sagi Mann (sagimann@gmail.com)
+ * @author psmith
  */
 public class JULAppenderTest extends TestCase {
     
     
-    java.util.logging.Logger julLogger;
-    Logger log;
-    AssertionHandler testHandler;
+    private java.util.logging.Logger julLogger;
+    private Logger log;
+    private AssertionHandler testHandler;
     
     
     public JULAppenderTest(String testName) {
@@ -46,6 +48,7 @@
         // Prepare the JUL logger to simulate a JUL environment
         // The logger is set to log only INFO-level events or higher.
         // During testing, a JUL handler will verify the activity of the logger.
+        LogManager.resetConfiguration();
         String julLoggerName = JULAppenderTest.class.getName();
         julLogger = java.util.logging.Logger.getLogger(julLoggerName);
         julLogger.setLevel(java.util.logging.Level.INFO);
@@ -57,6 +60,9 @@
         // It is set to log ALL events on purpose, in order to test JUL-Log4j
         // level inconsistencies.
         log = Logger.getLogger(JULAppenderTest.class);
+        if(log.getAllAppenders().hasMoreElements()) {
+            throw new IllegalStateException("Huh, there should be no appenders connected
to this logger");
+        }
         log.setLevel(Level.ALL);
         JULAppender appender = new JULAppender();
         appender.activateOptions();



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message