[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.29-4-g33a24d8

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Tue Jun 21 00:44:45 CEST 2011


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  33a24d81695f2a90ed239c0054225992c6be4aab (commit)
      from  218b66b5c0c7826c39abbc02e3728ad171bba8f8 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=33a24d81695f2a90ed239c0054225992c6be4aab
http://github.com/ceki/logback/commit/33a24d81695f2a90ed239c0054225992c6be4aab

commit 33a24d81695f2a90ed239c0054225992c6be4aab
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Tue Jun 21 00:35:19 2011 +0200

    Preparatory work for fixing LBCLASSIC-265. The first step is to detect
    SAX exceptions during Joran doConfigure invocation.

diff --git a/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java b/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java
index 678373a..dde4d7c 100644
--- a/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java
+++ b/logback-access/src/test/java/ch/qos/logback/access/db/DBAppenderIntegrationTest.java
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
 import java.util.Random;
 
 import ch.qos.logback.access.spi.IAccessEvent;
+import ch.qos.logback.core.status.StatusChecker;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -41,6 +42,7 @@ public class DBAppenderIntegrationTest {
 
   int diff = new Random(System.nanoTime()).nextInt(10000);
   AccessContext context = new AccessContext();
+  StatusChecker statusChecker = new StatusChecker(context);
   
   @BeforeClass
   public static void setUpBeforeClass() throws Exception {
@@ -74,7 +76,7 @@ public class DBAppenderIntegrationTest {
     StatusPrinter.print(context);
     
     // check that there were no errors
-    assertEquals(Status.INFO,  context.getStatusManager().getLevel());
+    assertEquals(Status.INFO,  statusChecker.getHighestLevel(0));
     
   }
   
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/GEventEvaluatorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/GEventEvaluatorTest.java
index 91661b2..752b1ed 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/boolex/GEventEvaluatorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/boolex/GEventEvaluatorTest.java
@@ -66,7 +66,7 @@ public class GEventEvaluatorTest {
     gee.start();
 
     StatusPrinter.printInCaseOfErrorsOrWarnings(context);
-    assertTrue(statusChecker.isErrorFree());
+    assertTrue(statusChecker.isErrorFree(0));
 
 
     boolean result = gee.evaluate(event);
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
index 2508c2b..aa72ae5 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/db/DBAppenderIntegrationTest.java
@@ -110,7 +110,7 @@ public class DBAppenderIntegrationTest {
 
     // check that there were no errors
     StatusChecker checker = new StatusChecker(lc);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
    
   }
 
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore211/Lbcore211.java b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore211/Lbcore211.java
new file mode 100644
index 0000000..20cc5d3
--- /dev/null
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore211/Lbcore211.java
@@ -0,0 +1,34 @@
+package ch.qos.logback.classic.issue.lbcore211;
+
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.util.StatusPrinter;
+import org.junit.Test;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author Ceki G&uuml;c&uuml;
+ */
+public class Lbcore211 {
+
+  @Test
+  public void lbcore211() throws JoranException {
+
+    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+    JoranConfigurator configurator = new JoranConfigurator();
+    configurator.setContext(lc);
+    lc.reset();
+    configurator.doConfigure("/home/ceki/lbcore211.xml");
+
+    Logger l = lc.getLogger("file.logger");
+    StatusPrinter.print(lc);
+    for (int i = 0; i < 10; i++) {
+      l.info("hello " + i);
+    }
+
+    lc.stop();
+  }
+}
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
index 3d8fb32..54c5f63 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/JoranConfiguratorTest.java
@@ -302,7 +302,7 @@ public class JoranConfiguratorTest {
 
     StatusPrinter.print(loggerContext);
     StatusChecker checker = new StatusChecker(loggerContext);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
     assertTrue(checker.containsMatch("Will reset and reconfigure context"));
   }
 
@@ -336,7 +336,7 @@ public class JoranConfiguratorTest {
     assertEquals("UTF-8", encoder.getCharset().displayName());
 
     StatusChecker checker = new StatusChecker(loggerContext);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
   }
 
   void verifyJULLevel(String loggerName, Level expectedLevel) {
@@ -363,7 +363,7 @@ public class JoranConfiguratorTest {
             + "/jul/levelChangePropagator0.xml";
     configure(configFileAsStr);
     StatusChecker checker = new StatusChecker(loggerContext);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
     verifyJULLevel("xx", null);
     verifyJULLevel("a.b.c", Level.WARN);
     verifyJULLevel(Logger.ROOT_LOGGER_NAME, Level.TRACE);
@@ -377,7 +377,7 @@ public class JoranConfiguratorTest {
             + "/jul/levelChangePropagator1.xml";
     configure(configFileAsStr);
     StatusChecker checker = new StatusChecker(loggerContext);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
     verifyJULLevel("xx", Level.INFO);
     verifyJULLevel("a.b.c", Level.WARN);
     verifyJULLevel(Logger.ROOT_LOGGER_NAME, Level.TRACE);
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
index 459656f..1d4ee9c 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/joran/conditional/ConditionalTest.java
@@ -80,7 +80,7 @@ public class ConditionalTest {
     ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
     assertNotNull(consoleAppender);
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
   }
 
   @SuppressWarnings("rawtypes")
@@ -97,7 +97,7 @@ public class ConditionalTest {
     ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
     assertNull(consoleAppender);
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
   }
 
   @SuppressWarnings("rawtypes")
@@ -120,7 +120,7 @@ public class ConditionalTest {
 
     // StatusPrinter.printIfErrorsOccured(context);
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
   }
 
 }
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
index 7f4f720..bb9bda4 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/TimeBasedRollingWithConfigFileTest.java
@@ -69,7 +69,7 @@ public class TimeBasedRollingWithConfigFileTest extends
     loadConfig(ClassicTestConstants.JORAN_INPUT_PREFIX + "rolling/" + testId
             + ".xml");
     StatusChecker sc = new StatusChecker(lc);
-    assertTrue(sc.isErrorFree());
+    assertTrue(sc.isErrorFree(0));
 
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
 
@@ -117,7 +117,7 @@ public class TimeBasedRollingWithConfigFileTest extends
             .getAppender("ROLLING");
 
     StatusChecker sc = new StatusChecker(lc);
-    assertTrue(sc.isErrorFree());
+    assertTrue(sc.isErrorFree(0));
 
     TimeBasedRollingPolicy tprp = (TimeBasedRollingPolicy<ILoggingEvent>) rfa
             .getTriggeringPolicy();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/UniqueFileTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/UniqueFileTest.java
index 4c13f00..5624e8c 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/rolling/UniqueFileTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/rolling/UniqueFileTest.java
@@ -56,7 +56,7 @@ public class UniqueFileTest {
     String timestamp = sdf.format(System.currentTimeMillis());
     
     StatusChecker sc = new StatusChecker(lc);
-    assertTrue(sc.isErrorFree());
+    assertTrue(sc.isErrorFree(0));
 
     Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);
     root.info("hello");
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
index cb21a9f..885e10f 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeTest.java
@@ -235,7 +235,7 @@ public class ReconfigureOnChangeTest {
   void verify(long expectedReconfigurations) {
     StatusChecker checker = new StatusChecker(loggerContext);
     StatusPrinter.print(loggerContext);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
     int effectiveResets = checker
             .matchCount("Will reset and reconfigure context");
     // the number of effective resets must be equal or less than
diff --git a/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java b/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
index 1fa41a8..1b4bb16 100644
--- a/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
+++ b/logback-classic/src/test/java/org/slf4j/impl/RecursiveInitializationTest.java
@@ -15,6 +15,7 @@ package org.slf4j.impl;
 
 import static org.junit.Assert.assertEquals;
 
+import ch.qos.logback.core.status.StatusChecker;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,8 +57,8 @@ public class RecursiveInitializationTest {
     LoggerContext loggerContext = (LoggerContext) LoggerFactory
         .getILoggerFactory();
     StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
-    StatusManager sm = loggerContext.getStatusManager();
-    assertEquals("Was expecting no errors", Status.WARN, sm.getLevel());
+    StatusChecker statusChecker = new StatusChecker(loggerContext);
+    assertEquals("Was expecting no errors", Status.WARN, statusChecker.getHighestLevel(0));
   }
 
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
index d04972e..3c624fa 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
@@ -130,4 +130,5 @@ public class CoreConstants {
 
   public static int BYTES_PER_INT = 4;
   public static final int MILLIS_IN_ONE_SECOND = 1000;
+  public final static String XML_PARSING_ERROR = "XML PARSING ERROR";
 }
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java b/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
index 294c2ea..9b6ac3a 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
@@ -131,9 +131,11 @@ public abstract class GenericConfigurator extends ContextAwareBase {
     synchronized (context.getConfigurationLock()) {
       interpreter.play(recorder.saxEventList);
     }
+
   }
 
-  public void doConfigure(final List<SaxEvent> eventList)
+  // protected since v0.9.30
+  protected void doConfigure(final List<SaxEvent> eventList)
       throws JoranException {
     buildInterpreter();
     EventPlayer player = new EventPlayer(interpreter);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java b/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
index 1b94111..5efbcd0 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/event/SaxEventRecorder.java
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import ch.qos.logback.core.CoreConstants;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
@@ -53,32 +54,36 @@ public class SaxEventRecorder extends DefaultHandler implements ContextAware {
 
   public List<SaxEvent> recordEvents(InputSource inputSource)
       throws JoranException {
-    SAXParser saxParser = null;
+    SAXParser saxParser = buildSaxParser();
+    try {
+      saxParser.parse(inputSource, this);
+      return saxEventList;
+    } catch (IOException ie) {
+      handleError(CoreConstants.XML_PARSING_ERROR+ ". I/O error occurred while parsing xml file", ie);
+    } catch(SAXException se) {
+      handleError(CoreConstants.XML_PARSING_ERROR+ ". Problem parsing XML document. See previously reported errors.", se);
+    } catch (Exception ex) {
+      handleError(CoreConstants.XML_PARSING_ERROR+ ". Unexpected exception while parsing XML document.", ex);
+    }
+    throw new IllegalStateException("This point can never be reached");
+  }
+
+  private void handleError(String errMsg, Throwable t) throws JoranException {
+    addError(errMsg, t);
+    throw new JoranException(errMsg, t);
+  }
+
+  private SAXParser buildSaxParser() throws JoranException {
     try {
       SAXParserFactory spf = SAXParserFactory.newInstance();
       spf.setValidating(false);
       spf.setNamespaceAware(true);
-      saxParser = spf.newSAXParser();
+      return spf.newSAXParser();
     } catch (Exception pce) {
       String errMsg = "Parser configuration error occured";
       addError(errMsg, pce);
       throw new JoranException(errMsg, pce);
     }
-
-    try {
-      saxParser.parse(inputSource, this);
-      return saxEventList;
-
-    } catch (IOException ie) {
-      String errMsg = "I/O error occurred while parsing xml file";
-      addError(errMsg, ie);
-      throw new JoranException(errMsg, ie);
-    } catch (Exception ex) {
-      String errMsg = "Problem parsing XML document. See previously reported errors. Abandoning all further processing.";
-      addError(errMsg, ex);
-      throw new JoranException(errMsg, ex);
-    }
-
   }
 
   public void startDocument() {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingJoranConfiguratorBase.java b/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingJoranConfiguratorBase.java
index 2a5184e..b5d5643 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingJoranConfiguratorBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingJoranConfiguratorBase.java
@@ -13,6 +13,7 @@
  */
 package ch.qos.logback.core.sift;
 
+import java.util.List;
 import java.util.Map;
 
 import ch.qos.logback.core.Appender;
@@ -20,7 +21,9 @@ import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.joran.GenericConfigurator;
 import ch.qos.logback.core.joran.action.NestedBasicPropertyIA;
 import ch.qos.logback.core.joran.action.NestedComplexPropertyIA;
+import ch.qos.logback.core.joran.event.SaxEvent;
 import ch.qos.logback.core.joran.spi.Interpreter;
+import ch.qos.logback.core.joran.spi.JoranException;
 
 public abstract class SiftingJoranConfiguratorBase<E> extends
     GenericConfigurator {
@@ -57,6 +60,9 @@ public abstract class SiftingJoranConfiguratorBase<E> extends
     if (errMsg != null && errorEmmissionCount < CoreConstants.MAX_ERROR_COUNT) {
       addError(errMsg);
     }
+  }
 
+  public void doConfigure(final List<SaxEvent> eventList) throws JoranException {
+    super.doConfigure(eventList);
   }
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/status/StatusChecker.java b/logback-core/src/main/java/ch/qos/logback/core/status/StatusChecker.java
similarity index 64%
rename from logback-core/src/test/java/ch/qos/logback/core/status/StatusChecker.java
rename to logback-core/src/main/java/ch/qos/logback/core/status/StatusChecker.java
index 2d023ab..207db5d 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/status/StatusChecker.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/status/StatusChecker.java
@@ -1,93 +1,113 @@
-/**
- * Logback: the reliable, generic, fast and flexible logging framework.
- * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
- *
- * This program and the accompanying materials are dual-licensed under
- * either the terms of the Eclipse Public License v1.0 as published by
- * the Eclipse Foundation
- *
- *   or (per the licensee's choosing)
- *
- * under the terms of the GNU Lesser General Public License version 2.1
- * as published by the Free Software Foundation.
- */
-package ch.qos.logback.core.status;
-
-import java.util.Iterator;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import ch.qos.logback.core.Context;
-
-public class StatusChecker {
-
-  StatusManager sm;
-
-  public StatusChecker(StatusManager sm) {
-    this.sm = sm;
-  }
-
-  public StatusChecker(Context context) {
-    this.sm = context.getStatusManager();
-  }
-  
-  public boolean isErrorFree() {
-    int level = sm.getLevel();
-    return level < Status.ERROR;
-  }
-  
-  public boolean containsMatch(int level, String regex) {
-    Pattern p = Pattern.compile(regex);
-
-    for(Status status: sm.getCopyOfStatusList()) {
-      if(level != status.getLevel()) {
-        continue;
-      }
-      String msg = status.getMessage();
-      Matcher matcher = p.matcher(msg);
-      if (matcher.lookingAt()) {
-        return true;
-      } 
-    }
-    return false;
-    
-  }
-  
-  public boolean containsMatch(String regex) {
-    Pattern p = Pattern.compile(regex);
-    for(Status status: sm.getCopyOfStatusList()) {
-      String msg = status.getMessage();
-      Matcher matcher = p.matcher(msg);
-      if (matcher.lookingAt()) {
-        return true;
-      } 
-    }
-    return false;
-  }
-
-  public int matchCount(String regex) {
-    int count = 0;
-    Pattern p = Pattern.compile(regex);
-    for(Status status: sm.getCopyOfStatusList()) {
-      String msg = status.getMessage();
-      Matcher matcher = p.matcher(msg);
-      if (matcher.lookingAt()) {
-        count++;
-      } 
-    }
-    return count;
-  }
-  
-  public boolean containsException(Class exceptionType) {
-    Iterator stati = sm.getCopyOfStatusList().iterator();
-    while (stati.hasNext()) {
-      Status status = (Status) stati.next();
-      Throwable t = status.getThrowable();
-      if (t != null && t.getClass().getName().equals(exceptionType.getName())) {
-        return true;
-      }
-    }
-    return false;
-  }
-
-}
+/**
+ * Logback: the reliable, generic, fast and flexible logging framework.
+ * Copyright (C) 1999-2011, QOS.ch. All rights reserved.
+ *
+ * This program and the accompanying materials are dual-licensed under
+ * either the terms of the Eclipse Public License v1.0 as published by
+ * the Eclipse Foundation
+ *
+ *   or (per the licensee's choosing)
+ *
+ * under the terms of the GNU Lesser General Public License version 2.1
+ * as published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.status;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import ch.qos.logback.core.Context;
+
+public class StatusChecker {
+
+  StatusManager sm;
+
+  public StatusChecker(StatusManager sm) {
+    this.sm = sm;
+  }
+
+  public StatusChecker(Context context) {
+    this.sm = context.getStatusManager();
+  }
+
+  private List<Status> filterStatusListByTimeThreshold(List<Status> rawList, long threshold) {
+    List<Status> filteredList = new ArrayList<Status>();
+    for (Status s : rawList) {
+      if (s.getDate() >= threshold)
+        filteredList.add(s);
+    }
+    return filteredList;
+  }
+
+  public int getHighestLevel(long threshold) {
+    List<Status> filteredList = filterStatusListByTimeThreshold(sm.getCopyOfStatusList(), threshold);
+    int maxLevel = Status.INFO;
+    for (Status s : filteredList) {
+      if(s.getLevel() > maxLevel)
+        maxLevel = s.getLevel();
+    }
+    return maxLevel;
+  }
+
+  public boolean isErrorFree(long threshold) {
+    return Status.ERROR > getHighestLevel(threshold);
+  }
+
+  public boolean containsMatch(int level, String regex) {
+    Pattern p = Pattern.compile(regex);
+
+    for (Status status : sm.getCopyOfStatusList()) {
+      if (level != status.getLevel()) {
+        continue;
+      }
+      String msg = status.getMessage();
+      Matcher matcher = p.matcher(msg);
+      if (matcher.lookingAt()) {
+        return true;
+      }
+    }
+    return false;
+
+  }
+
+  public boolean containsMatch(String regex) {
+    Pattern p = Pattern.compile(regex);
+    for (Status status : sm.getCopyOfStatusList()) {
+      String msg = status.getMessage();
+      Matcher matcher = p.matcher(msg);
+      if (matcher.lookingAt()) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  public int matchCount(String regex) {
+    int count = 0;
+    Pattern p = Pattern.compile(regex);
+    for (Status status : sm.getCopyOfStatusList()) {
+      String msg = status.getMessage();
+      Matcher matcher = p.matcher(msg);
+      if (matcher.lookingAt()) {
+        count++;
+      }
+    }
+    return count;
+  }
+
+  public boolean containsException(Class exceptionType) {
+    Iterator stati = sm.getCopyOfStatusList().iterator();
+    while (stati.hasNext()) {
+      Status status = (Status) stati.next();
+      Throwable t = status.getThrowable();
+      if (t != null && t.getClass().getName().equals(exceptionType.getName())) {
+        return true;
+      }
+    }
+    return false;
+  }
+
+}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/status/StatusManager.java b/logback-core/src/main/java/ch/qos/logback/core/status/StatusManager.java
index 46410cd..f64fa7c 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/status/StatusManager.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/status/StatusManager.java
@@ -41,7 +41,7 @@ public interface StatusManager {
    * 
    * @return
    */
-  public int getLevel();
+  //public int getLevel();
 
   /**
    * Return the number of status entries.
diff --git a/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java b/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
index 4f60696..40394cd 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
@@ -22,6 +22,7 @@ import ch.qos.logback.core.CoreConstants;
 import ch.qos.logback.core.helpers.ThrowableToStringArray;
 import ch.qos.logback.core.status.ErrorStatus;
 import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusChecker;
 import ch.qos.logback.core.status.StatusManager;
 
 public class StatusPrinter {
@@ -51,7 +52,8 @@ public class StatusPrinter {
       ps.println("WARN: Context named \"" + context.getName()
           + "\" has no status manager");
     } else {
-      if (sm.getLevel() == ErrorStatus.WARN || (sm.getLevel() == ErrorStatus.ERROR) ) {
+      StatusChecker sc = new StatusChecker(context);
+      if (sc.getHighestLevel(0) >= ErrorStatus.WARN) {
         print(sm);
       }
     }
@@ -73,7 +75,8 @@ public class StatusPrinter {
       ps.println("WARN: Context named \"" + context.getName()
           + "\" has no status manager");
     } else {
-      if (sm.getLevel() == ErrorStatus.ERROR) {
+      StatusChecker sc = new StatusChecker(context);
+      if (sc.getHighestLevel(0) == ErrorStatus.ERROR) {
         print(sm);
       }
     }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
index 3a9616a..0250640 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/appender/FileAppenderTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue;
 import java.io.File;
 import java.util.List;
 
+import ch.qos.logback.core.status.StatusChecker;
 import org.junit.Test;
 
 import ch.qos.logback.core.Appender;
@@ -110,8 +111,9 @@ public class FileAppenderTest extends AbstractAppenderTest<Object> {
     assertTrue(appender.isAppend());
 
     StatusManager sm = context.getStatusManager();
-    StatusPrinter.print(context);
-    assertEquals(Status.WARN, sm.getLevel());
+    //StatusPrinter.print(context);
+    StatusChecker statusChecker = new StatusChecker(context);
+    assertEquals(Status.WARN, statusChecker.getHighestLevel(0));
     List<Status> statusList = sm.getCopyOfStatusList();
     assertTrue("Expecting status list size to be 2 or larger, but was "
         + statusList.size(), statusList.size() >= 2);
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfiguratorTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfiguratorTest.java
index a09fedc..f8ce354 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfiguratorTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfiguratorTest.java
@@ -27,6 +27,7 @@ import java.util.HashMap;
 import java.util.jar.JarOutputStream;
 import java.util.zip.ZipEntry;
 
+import ch.qos.logback.core.CoreConstants;
 import org.junit.Test;
 
 import ch.qos.logback.core.Context;
@@ -99,8 +100,7 @@ public class TrivialConfiguratorTest {
     Status s1 = tsl.list.get(1);
     assertTrue(s1
         .getMessage()
-        .startsWith(
-            "Problem parsing XML document. See previously reported errors. Abandoning all further processing."));
+        .startsWith(CoreConstants.XML_PARSING_ERROR));
   }
 
   @Test
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
index 9c26831..379a804 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncludeActionTest.java
@@ -51,6 +51,7 @@ public class IncludeActionTest {
   final static String SECOND_FILE_KEY = "secondFileKey";
 
   Context context = new ContextBase();
+  StatusChecker statusChecker = new StatusChecker(context);
   TrivialConfigurator tc;
 
   static final String INCLUSION_DIR_PREFIX = CoreTestConstants.JORAN_INPUT_PREFIX
@@ -130,9 +131,8 @@ public class IncludeActionTest {
   public void noFileFound() throws JoranException {
     System.setProperty(INCLUDE_KEY, "toto");
     tc.doConfigure(TOP_BY_FILE);
-    assertEquals(Status.ERROR, context.getStatusManager().getLevel());
-    StatusChecker sc = new StatusChecker(context.getStatusManager());
-    assertTrue(sc.containsException(FileNotFoundException.class));
+    assertEquals(Status.ERROR, statusChecker.getHighestLevel(0));
+    assertTrue(statusChecker.containsException(FileNotFoundException.class));
   }
 
   @Test
@@ -140,9 +140,8 @@ public class IncludeActionTest {
     String tmpOut = copyToTemp(INVALID);
     System.setProperty(INCLUDE_KEY, tmpOut);
     tc.doConfigure(TOP_BY_FILE);
-    assertEquals(Status.ERROR, context.getStatusManager().getLevel());
-    StatusChecker sc = new StatusChecker(context.getStatusManager());
-    assertTrue(sc.containsException(SAXParseException.class));
+    assertEquals(Status.ERROR, statusChecker.getHighestLevel(0));
+    assertTrue(statusChecker.containsException(SAXParseException.class));
 
     // we like to erase the temp file in order to see
     // if http://jira.qos.ch/browse/LBCORE-122 was fixed
@@ -169,23 +168,20 @@ public class IncludeActionTest {
   public void malformedURL() throws JoranException {
     System.setProperty(INCLUDE_KEY, "htp://logback.qos.ch");
     tc.doConfigure(TOP_BY_URL);
-    assertEquals(Status.ERROR, context.getStatusManager().getLevel());
-    StatusChecker sc = new StatusChecker(context.getStatusManager());
-    assertTrue(sc.containsException(MalformedURLException.class));
+    assertEquals(Status.ERROR, statusChecker.getHighestLevel(0));
+    assertTrue(statusChecker.containsException(MalformedURLException.class));
   }
 
   @Test
   public void unknownURL() throws JoranException {
     System.setProperty(INCLUDE_KEY, "http://logback2345.qos.ch");
     tc.doConfigure(TOP_BY_URL);
-    assertEquals(Status.ERROR, context.getStatusManager().getLevel());
-    StatusChecker sc = new StatusChecker(context.getStatusManager()); 
-
+    assertEquals(Status.ERROR, statusChecker.getHighestLevel(0));
     // OS X throws IOException instead of UnknownHostException
     // http://jira.qos.ch/browse/LBCORE-129
     // This behavior has been observed on Windows XP as well
-    assertTrue(sc.containsException(UnknownHostException.class)
-        || sc.containsException(IOException.class));
+    assertTrue(statusChecker.containsException(UnknownHostException.class)
+        || statusChecker.containsException(IOException.class));
   }
 
   @Test
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
index 30a042f..86acd87 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/conditional/IfThenElseTest.java
@@ -95,7 +95,7 @@ public class IfThenElseTest {
     tc.doConfigure(CONDITIONAL_DIR_PREFIX+"ifWithoutElse.xml");
     verifyConfig(new String[] {"BEGIN", "END"});
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
   }
 
   
diff --git a/logback-core/src/test/java/ch/qos/logback/core/joran/event/SaxEventRecorderTest.java b/logback-core/src/test/java/ch/qos/logback/core/joran/event/SaxEventRecorderTest.java
index c7f7552..9a68ef7 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/joran/event/SaxEventRecorderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/joran/event/SaxEventRecorderTest.java
@@ -21,6 +21,7 @@ import java.util.List;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.SAXParserFactory;
 
+import ch.qos.logback.core.status.StatusChecker;
 import org.junit.Test;
 import org.xml.sax.Attributes;
 
@@ -38,7 +39,7 @@ import ch.qos.logback.core.util.CoreTestConstants;
 public class SaxEventRecorderTest {
 
   Context context =  new ContextBase();
-
+  StatusChecker statusChecker = new StatusChecker(context);
 
   SAXParser createParser() throws Exception {
     SAXParserFactory spf = SAXParserFactory.newInstance();
@@ -65,8 +66,7 @@ public class SaxEventRecorderTest {
   @Test
   public void test1() throws Exception {
     List<SaxEvent> seList = doTest("event1.xml");
-    StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
+    assertTrue(statusChecker.getHighestLevel(0) == Status.INFO);
     //dump(seList);  
     assertEquals(11, seList.size());
   }
@@ -75,7 +75,7 @@ public class SaxEventRecorderTest {
   public void test2() throws Exception {
     List<SaxEvent> seList = doTest("ampEvent.xml");
     StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
+    assertTrue(statusChecker.getHighestLevel(0) == Status.INFO);
     //dump(seList);  
     assertEquals(3, seList.size());
     
@@ -87,8 +87,8 @@ public class SaxEventRecorderTest {
   public void test3() throws Exception {
     List<SaxEvent> seList = doTest("inc.xml");
     StatusManager sm = context.getStatusManager();
-    assertTrue(sm.getLevel() == Status.INFO);
-    //dump(seList);  
+    assertTrue(statusChecker.getHighestLevel(0) == Status.INFO);
+    //dump(seList);
     assertEquals(4, seList.size());
     
     StartEvent se = (StartEvent) seList.get(1);
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/MultiThreadedRollingTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/MultiThreadedRollingTest.java
index 3084601..8e056e2 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/MultiThreadedRollingTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/MultiThreadedRollingTest.java
@@ -255,7 +255,7 @@ public class MultiThreadedRollingTest {
     multiThreadedHarness.execute(runnableArray);
 
     StatusChecker checker = new StatusChecker(context.getStatusManager());
-    if (!checker.isErrorFree()) {
+    if (!checker.isErrorFree(0)) {
       StatusPrinter.print(context);
       fail("errors reported");
     }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
index fd8888b..05f5891 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RenameUtilTest.java
@@ -68,7 +68,7 @@ public class RenameUtilTest {
 
     renameUtil.rename(fromFile.toString(), new File(randomTARGETDir + "/to.test").toString());
     StatusPrinter.printInCaseOfErrorsOrWarnings(context);
-    assertTrue(statusChecker.isErrorFree());
+    assertTrue(statusChecker.isErrorFree(0));
   }
 
 }
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
index 718a66b..d1b2b06 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/RollingFileAppenderTest.java
@@ -107,9 +107,9 @@ public class RollingFileAppenderTest extends AbstractAppenderTest<Object> {
 
     rfa.start();
 
-    StatusManager sm = context.getStatusManager();
+    StatusChecker checker = new StatusChecker(context);
     assertFalse(rfa.isStarted());
-    assertEquals(Status.ERROR, sm.getLevel());
+    assertEquals(Status.ERROR, checker.getHighestLevel(0));
   }
 
   @Test
diff --git a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
index 865a579..a08db12 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/rolling/helper/CompressTest.java
@@ -87,7 +87,7 @@ public class CompressTest {
         + "compress1.txt.gz", null);
 
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
     assertTrue(Compare.gzCompare(CoreTestConstants.OUTPUT_DIR_PREFIX
         + "compress1.txt.gz", CoreTestConstants.TEST_DIR_PREFIX
         + "witness/compress1.txt.gz"));
@@ -102,7 +102,7 @@ public class CompressTest {
         + "compress2.txt", null);
 
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
 
     assertTrue(Compare.gzCompare(CoreTestConstants.OUTPUT_DIR_PREFIX
         + "compress2.txt.gz", CoreTestConstants.TEST_DIR_PREFIX
@@ -117,7 +117,7 @@ public class CompressTest {
         + "input/compress3.txt", CoreTestConstants.OUTPUT_DIR_PREFIX
         + "compress3.txt", "compress3.txt");
     StatusChecker checker = new StatusChecker(context);
-    assertTrue(checker.isErrorFree());
+    assertTrue(checker.isErrorFree(0));
 
     // we don't know how to compare .zip files
     // assertTrue(Compare.compare(CoreTestConstants.OUTPUT_DIR_PREFIX

-----------------------------------------------------------------------

Summary of changes:
 .../access/db/DBAppenderIntegrationTest.java       |    4 +-
 .../classic/boolex/GEventEvaluatorTest.java        |    2 +-
 .../classic/db/DBAppenderIntegrationTest.java      |    2 +-
 .../logback/classic/issue/lbcore211/Lbcore211.java |   34 ++++
 .../classic/joran/JoranConfiguratorTest.java       |    8 +-
 .../classic/joran/conditional/ConditionalTest.java |    6 +-
 .../TimeBasedRollingWithConfigFileTest.java        |    4 +-
 .../logback/classic/rolling/UniqueFileTest.java    |    2 +-
 .../classic/turbo/ReconfigureOnChangeTest.java     |    2 +-
 .../slf4j/impl/RecursiveInitializationTest.java    |    5 +-
 .../java/ch/qos/logback/core/CoreConstants.java    |    1 +
 .../logback/core/joran/GenericConfigurator.java    |    4 +-
 .../logback/core/joran/event/SaxEventRecorder.java |   39 ++--
 .../core/sift/SiftingJoranConfiguratorBase.java    |    6 +
 .../ch/qos/logback/core/status/StatusChecker.java  |  206 +++++++++++---------
 .../ch/qos/logback/core/status/StatusManager.java  |    2 +-
 .../ch/qos/logback/core/util/StatusPrinter.java    |    7 +-
 .../logback/core/appender/FileAppenderTest.java    |    6 +-
 .../core/joran/TrivialConfiguratorTest.java        |    4 +-
 .../core/joran/action/IncludeActionTest.java       |   24 +--
 .../core/joran/conditional/IfThenElseTest.java     |    2 +-
 .../core/joran/event/SaxEventRecorderTest.java     |   12 +-
 .../core/rolling/MultiThreadedRollingTest.java     |    2 +-
 .../qos/logback/core/rolling/RenameUtilTest.java   |    2 +-
 .../core/rolling/RollingFileAppenderTest.java      |    4 +-
 .../logback/core/rolling/helper/CompressTest.java  |    6 +-
 26 files changed, 234 insertions(+), 162 deletions(-)
 create mode 100644 logback-classic/src/test/java/ch/qos/logback/classic/issue/lbcore211/Lbcore211.java
 rename logback-core/src/{test => main}/java/ch/qos/logback/core/status/StatusChecker.java (64%)


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list