[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.28-49-g7117a1f

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Thu Jun 9 23:31:44 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  7117a1fff64207903d99bfbd4d89de3c5d70eafe (commit)
      from  138ac6971a6052445019f7629a22cf83d4e78d6c (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=7117a1fff64207903d99bfbd4d89de3c5d70eafe
http://github.com/ceki/logback/commit/7117a1fff64207903d99bfbd4d89de3c5d70eafe

commit 7117a1fff64207903d99bfbd4d89de3c5d70eafe
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Thu Jun 9 23:24:31 2011 +0200

    fixing LBCLASSIC-247

diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
index 666ebfd..c514c68 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/turbo/ReconfigureOnChangeFilter.java
@@ -110,7 +110,6 @@ public class ReconfigureOnChangeFilter extends TurboFilter {
   // reader lock.
   private void detachReconfigurationToNewThread() {
     addInfo("Detected change in [" + cwl.getCopyOfFileWatchList() + "]");
-    addInfo("Resetting and reconfiguring context [" + context.getName() + "]");
     new ReconfiguringThread().start();
   }
 
@@ -141,17 +140,13 @@ public class ReconfigureOnChangeFilter extends TurboFilter {
 
   class ReconfiguringThread extends Thread {
     public void run() {
+      if(mainConfigurationURL == null) {
+        addInfo("Due to missing top level configuration file, skipping reconfiguration");
+        return;
+      }
       LoggerContext lc = (LoggerContext) context;
-      if (mainConfigurationURL.toString().endsWith("groovy")) {
-        if (EnvUtil.isGroovyAvailable()) {
-          lc.reset();
-          // avoid directly referring to GafferConfigurator so as to avoid
-          // loading  groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214
-          GafferUtil.runGafferConfiguratorOn(lc, this, mainConfigurationURL);
-        } else {
-          addError("Groovy classes are not available on the class path. ABORTING INITIALIZATION.");
-        }
-      } else if (mainConfigurationURL.toString().endsWith("xml")) {
+      addInfo("Will reset and reconfigure context named [" + context.getName() + "]");
+      if (mainConfigurationURL.toString().endsWith("xml")) {
         JoranConfigurator jc = new JoranConfigurator();
         jc.setContext(context);
         lc.reset();
@@ -162,6 +157,15 @@ public class ReconfigureOnChangeFilter extends TurboFilter {
         } catch (JoranException e) {
           addError("Failure during reconfiguration", e);
         }
+      } else if (mainConfigurationURL.toString().endsWith("groovy")) {
+        if (EnvUtil.isGroovyAvailable()) {
+          lc.reset();
+          // avoid directly referring to GafferConfigurator so as to avoid
+          // loading  groovy.lang.GroovyObject . See also http://jira.qos.ch/browse/LBCLASSIC-214
+          GafferUtil.runGafferConfiguratorOn(lc, this, mainConfigurationURL);
+        } else {
+          addError("Groovy classes are not available on the class path. ABORTING INITIALIZATION.");
+        }
       }
     }
   }
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 7fe39f2..cb21a9f 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
@@ -16,13 +16,13 @@ package ch.qos.logback.classic.turbo;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.io.File;
-import java.io.IOException;
+import java.io.*;
 import java.net.MalformedURLException;
 import java.util.Random;
 
 import ch.qos.logback.classic.gaffer.GafferConfigurator;
 import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
+import org.hsqldb.lib.StringInputStream;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -107,6 +107,12 @@ public class ReconfigureOnChangeTest {
     jc.doConfigure(file);
   }
 
+  void configure(InputStream is) throws JoranException {
+    JoranConfigurator jc = new JoranConfigurator();
+    jc.setContext(loggerContext);
+    jc.doConfigure(is);
+  }
+
   void gConfigure(File file) throws JoranException {
     GafferConfigurator gc = new GafferConfigurator(loggerContext);
     gc.run(file);
@@ -122,8 +128,11 @@ public class ReconfigureOnChangeTest {
   }
 
 
-  void doScanTest(File topLevelFile, File fileToTouch) throws JoranException, IOException, InterruptedException {
-    configure(topLevelFile);
+  void doScanTest(File fileToTouch) throws JoranException, IOException, InterruptedException {
+    doScanTest(fileToTouch, false);
+  }
+
+  void doScanTest(File fileToTouch, boolean forcedReconfigurationSkip) throws JoranException, IOException, InterruptedException {
     RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(fileToTouch);
     harness.execute(runnableArray);
 
@@ -131,8 +140,10 @@ public class ReconfigureOnChangeTest {
             new InfoStatus("end of execution ", this));
 
     long expectedReconfigurations = runnableArray[0].getCounter();
-    verify(expectedReconfigurations);
+    if(forcedReconfigurationSkip)
+      expectedReconfigurations = 0;
 
+    verify(expectedReconfigurations);
   }
 
   // chose a test at random. These tests are rather long...
@@ -155,24 +166,39 @@ public class ReconfigureOnChangeTest {
   }
 
   // Tests whether ConfigurationAction is installing ReconfigureOnChangeFilter
+  @Test
   public void scan1() throws JoranException, IOException, InterruptedException {
     File file = new File(SCAN1_FILE_AS_STR);
-    doScanTest(file, file);
+    configure(file);
+    doScanTest(file);
   }
 
+  @Test
   public void scanWithFileInclusion() throws JoranException, IOException, InterruptedException {
     File topLevelFile = new File(INCLUSION_SCAN_TOPLEVEL0_AS_STR);
     File innerFile = new File(INCLUSION_SCAN_INNER0_AS_STR);
-    doScanTest(topLevelFile, innerFile);
+    configure(topLevelFile);
+    doScanTest(innerFile);
   }
 
+  @Test
   public void scanWithResourceInclusion() throws JoranException, IOException, InterruptedException {
     File topLevelFile = new File(INCLUSION_SCAN_TOP_BY_RESOURCE_AS_STR);
     File innerFile = new File(INCLUSION_SCAN_INNER1_AS_STR);
-    doScanTest(topLevelFile, innerFile);
+    configure(topLevelFile);
+    doScanTest(innerFile);
   }
 
+  // See also http://jira.qos.ch/browse/LBCLASSIC-247
+  @Test
+  public void includeScanViaInputStreamSuppliedConfigFile() throws IOException, JoranException, InterruptedException {
+    String configurationStr = "<configuration scan=\"true\" scanPeriod=\"50 millisecond\"><include resource=\"asResource/inner1.xml\"/></configuration>";
+    configure(new ByteArrayInputStream(configurationStr.getBytes("UTF-8")));
+    File innerFile = new File(INCLUSION_SCAN_INNER1_AS_STR);
+    doScanTest(innerFile, true);
+  }
 
+  @Test
   public void gscan1() throws JoranException, IOException, InterruptedException {
     File file = new File(G_SCAN1_FILE_AS_STR);
     gConfigure(file);
@@ -188,6 +214,7 @@ public class ReconfigureOnChangeTest {
 
   // check for deadlocks
   //Attr_Test(timeout = 20000)
+  @Test
   public void scan_lbclassic154() throws JoranException, IOException,
           InterruptedException {
     File file = new File(SCAN_LBCLASSIC_154_FILE_AS_STR);
@@ -203,14 +230,19 @@ public class ReconfigureOnChangeTest {
   }
 
 
+
+
   void verify(long expectedReconfigurations) {
     StatusChecker checker = new StatusChecker(loggerContext);
     StatusPrinter.print(loggerContext);
     assertTrue(checker.isErrorFree());
     int effectiveResets = checker
-            .matchCount("Resetting and reconfiguring context");
+            .matchCount("Will reset and reconfigure context");
     // the number of effective resets must be equal or less than
     // expectedReconfigurations
+    System.out.println("effectiveResets="+effectiveResets);
+
+    System.out.println("expectedReconfigurations="+expectedReconfigurations);
     assertTrue(effectiveResets <= expectedReconfigurations);
 
     // however, there should be some effective resets
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 2881ad0..d04972e 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
@@ -112,6 +112,7 @@ public class CoreConstants {
   static public final String SEE_FNP_NOT_SET = "See also http://logback.qos.ch/codes.html#tbr_fnp_not_set";
 
   public static String CONFIGURATION_WATCH_LIST = "CONFIGURATION_WATCH_LIST";
+  public static String CONFIGURATION_WATCH_LIST_RESET = "CONFIGURATION_WATCH_LIST_RESET";
 
 
   /**
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 22970fa..294c2ea 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
@@ -115,8 +115,14 @@ public abstract class GenericConfigurator extends ContextAwareBase {
     addDefaultNestedComponentRegistryRules(ec.getDefaultNestedComponentRegistry());
   }
 
+  // this is the most inner form of doConfigure whereto other doConfigure
+  // methods ultimately delegate
   final public void doConfigure(final InputSource inputSource)
       throws JoranException {
+
+    if(!ConfigurationWatchListUtil.wasConfigurationWatchListReset(context)) {
+      informContextOfURLUsedForConfiguration(null);
+    }
     SaxEventRecorder recorder = new SaxEventRecorder();
     recorder.setContext(context);
     recorder.recordEvents(inputSource);
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java
index 9ce695d..c134ecc 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/spi/ConfigurationWatchList.java
@@ -37,9 +37,15 @@ public class ConfigurationWatchList extends ContextAwareBase {
     fileWatchList.clear();
   }
 
+  /**
+   * The mainURL for the configuration file. Null values are allowed.
+   * @param mainURL
+   */
   public void setMainURL(URL mainURL) {
+    // main url can be null
     this.mainURL = mainURL;
-    addAsFileToWatch(mainURL);
+    if (mainURL != null)
+      addAsFileToWatch(mainURL);
   }
 
   private void addAsFileToWatch(URL url) {
@@ -58,9 +64,10 @@ public class ConfigurationWatchList extends ContextAwareBase {
     return mainURL;
   }
 
-  public List<File>  getCopyOfFileWatchList() {
+  public List<File> getCopyOfFileWatchList() {
     return new ArrayList<File>(fileWatchList);
   }
+
   public boolean changeDetected() {
     int len = fileWatchList.size();
     for (int i = 0; i < len; i++) {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/util/ConfigurationWatchListUtil.java b/logback-core/src/main/java/ch/qos/logback/core/joran/util/ConfigurationWatchListUtil.java
index 2c7955f..6e61408 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/util/ConfigurationWatchListUtil.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/util/ConfigurationWatchListUtil.java
@@ -46,6 +46,7 @@ public class ConfigurationWatchListUtil {
     } else {
       cwl.clear();
     }
+    setConfigurationWatchListResetFlag(context, true);
     cwl.setMainURL(url);
   }
 
@@ -59,6 +60,18 @@ public class ConfigurationWatchListUtil {
     }
   }
 
+  public static boolean wasConfigurationWatchListReset(Context context) {
+    Object o = context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST_RESET);
+    if(o == null)
+      return false;
+    else {
+      return ((Boolean) o).booleanValue();
+    }
+  }
+  public static void setConfigurationWatchListResetFlag(Context context, boolean val) {
+    context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST_RESET, new Boolean(val));
+  }
+
   public static ConfigurationWatchList getConfigurationWatchList(Context context) {
     return (ConfigurationWatchList) context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST);
   }

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

Summary of changes:
 .../classic/turbo/ReconfigureOnChangeFilter.java   |   26 ++++++----
 .../classic/turbo/ReconfigureOnChangeTest.java     |   50 ++++++++++++++++----
 .../java/ch/qos/logback/core/CoreConstants.java    |    1 +
 .../logback/core/joran/GenericConfigurator.java    |    6 ++
 .../core/joran/spi/ConfigurationWatchList.java     |   11 ++++-
 .../joran/util/ConfigurationWatchListUtil.java     |   13 +++++
 6 files changed, 85 insertions(+), 22 deletions(-)


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


More information about the logback-dev mailing list