[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.27-22-gb3b234d
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Mon Jan 24 23:22:45 CET 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 b3b234ddef5a1ba6863cd922f4f410cde65c1a0d (commit)
from d411638322b2a2291ac1c85e5a596aeb16c8de64 (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=b3b234ddef5a1ba6863cd922f4f410cde65c1a0d
http://github.com/ceki/logback/commit/b3b234ddef5a1ba6863cd922f4f410cde65c1a0d
commit b3b234ddef5a1ba6863cd922f4f410cde65c1a0d
Author: Ceki Gulcu <ceki at qos.ch>
Date: Mon Jan 24 23:19:36 2011 +0100
minor refactoring
diff --git a/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/GafferConfigurator.groovy b/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/GafferConfigurator.groovy
index 7736256..c4be351 100644
--- a/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/GafferConfigurator.groovy
+++ b/logback-classic/src/main/groovy/ch/qos/logback/classic/gaffer/GafferConfigurator.groovy
@@ -29,7 +29,7 @@ class GafferConfigurator {
}
protected void informContextOfURLUsedForConfiguration(URL url) {
- ConfigurationWatchListUtil.updateWatchList(context, url);
+ ConfigurationWatchListUtil.setMainWatchURL(context, url);
}
void run(URL url) {
diff --git a/logback-classic/src/test/input/turbo/scan_lbclassic154.xml b/logback-classic/src/test/input/turbo/scan_lbclassic154.xml
index 0980beb..735c54c 100644
--- a/logback-classic/src/test/input/turbo/scan_lbclassic154.xml
+++ b/logback-classic/src/test/input/turbo/scan_lbclassic154.xml
@@ -1,5 +1,3 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!DOCTYPE configuration>
<configuration scan="true" scanPeriod="50 millisecond">
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 ee96b45..67a534f 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
@@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
+import java.util.Random;
import ch.qos.logback.classic.gaffer.GafferConfigurator;
import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
@@ -49,13 +50,25 @@ public class ReconfigureOnChangeTest {
// the space in the file name mandated by
// http://jira.qos.ch/browse/LBCORE-119
final static String SCAN1_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX
- + "turbo/scan 1.xml";
+ + "turbo/scan 1.xml";
- final static String G_SCAN1_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX
- + "turbo/scan 1.groovy";
+ final static String G_SCAN1_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX
+ + "turbo/scan 1.groovy";
final static String SCAN_LBCLASSIC_154_FILE_AS_STR = ClassicTestConstants.INPUT_PREFIX
- + "turbo/scan_lbclassic154.xml";
+ + "turbo/scan_lbclassic154.xml";
+
+ final static String INCLUSION_SCAN_TOPLEVEL0_AS_STR = ClassicTestConstants.INPUT_PREFIX
+ + "turbo/inclusion/topLevel0.xml";
+
+ final static String INCLUSION_SCAN_TOP_BY_RESOURCE_AS_STR = ClassicTestConstants.INPUT_PREFIX
+ + "turbo/inclusion/topByResource.xml";
+
+
+ final static String INCLUSION_SCAN_INNER0_AS_STR = ClassicTestConstants.INPUT_PREFIX
+ + "turbo/inclusion/inner0.xml";
+
+ final static String INCLUSION_SCAN_INNER1_AS_STR = "target/test-classes/asResource/inner1.xml";
// it actually takes time for Windows to propagate file modification changes
// values below 100 milliseconds can be problematic the same propagation
@@ -72,7 +85,7 @@ public class ReconfigureOnChangeTest {
@Before
public void setUp() {
- System.out.println("======== TEST START, time"+System.currentTimeMillis());
+ System.out.println("======== TEST START, time" + System.currentTimeMillis());
// take into account propagation latency occurs on Linux or Mac
if (Env.isLinux() || Env.isMac()) {
sleepBetweenUpdates = 950;
@@ -109,22 +122,57 @@ 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);
- configure(file);
- RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(file);
+ void doScanTest(File topLevelFile, File fileToTouch) throws JoranException, IOException, InterruptedException {
+ configure(topLevelFile);
+ RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(fileToTouch);
harness.execute(runnableArray);
loggerContext.getStatusManager().add(
- new InfoStatus("end of execution ", this));
+ new InfoStatus("end of execution ", this));
long expectedReconfigurations = runnableArray[0].getCounter();
verify(expectedReconfigurations);
+
}
- @Test
+ // chose a test at random. These tests are rather long...
+ // check for deadlocks
+ @Test(timeout = 20000)
+ public void randomTest() throws JoranException, IOException, InterruptedException {
+ Random rand = new Random(System.currentTimeMillis());
+ switch(rand.nextInt(5)) {
+ case 0: scan1();
+ break;
+ case 1: scanWithFileInclusion();
+ break;
+ case 2: scanWithResourceInclusion();
+ break;
+ case 3: scan_lbclassic154();
+ break;
+ case 4: gscan1();
+ break;
+ }
+ }
+
+ // Tests whether ConfigurationAction is installing ReconfigureOnChangeFilter
+ public void scan1() throws JoranException, IOException, InterruptedException {
+ File file = new File(SCAN1_FILE_AS_STR);
+ doScanTest(file, file);
+ }
+
+ 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);
+ }
+
+ 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);
+ }
+
+
public void gscan1() throws JoranException, IOException, InterruptedException {
File file = new File(G_SCAN1_FILE_AS_STR);
gConfigure(file);
@@ -132,45 +180,46 @@ public class ReconfigureOnChangeTest {
harness.execute(runnableArray);
loggerContext.getStatusManager().add(
- new InfoStatus("end of execution ", this));
+ new InfoStatus("end of execution ", this));
long expectedRreconfigurations = runnableArray[0].getCounter();
verify(expectedRreconfigurations);
}
// check for deadlocks
- @Test(timeout = 20000)
+ //Attr_Test(timeout = 20000)
public void scan_lbclassic154() throws JoranException, IOException,
- InterruptedException {
+ InterruptedException {
File file = new File(SCAN_LBCLASSIC_154_FILE_AS_STR);
configure(file);
RunnableWithCounterAndDone[] runnableArray = buildRunnableArray(file);
harness.execute(runnableArray);
loggerContext.getStatusManager().add(
- new InfoStatus("end of execution ", this));
+ new InfoStatus("end of execution ", this));
long expectedReconfigurations = runnableArray[0].getCounter();
verify(expectedReconfigurations);
}
+
void verify(long expectedReconfigurations) {
StatusChecker checker = new StatusChecker(loggerContext);
StatusPrinter.print(loggerContext);
assertTrue(checker.isErrorFree());
int effectiveResets = checker
- .matchCount("Resetting and reconfiguring context");
+ .matchCount("Resetting and reconfiguring context");
// the number of effective resets must be equal or less than
// expectedReconfigurations
assertTrue(effectiveResets <= expectedReconfigurations);
// however, there should be some effective resets
String failMsg = "effective=" + effectiveResets + ", expected="
- + expectedReconfigurations;
+ + expectedReconfigurations;
// we can't have the test succeed under JDK 1.5, punt and require 1.6+
if (Env.isJDK6OrHigher()) {
assertTrue(failMsg,
- (effectiveResets * 1.5) >= (expectedReconfigurations * 1.0));
+ (effectiveResets * 1.5) >= (expectedReconfigurations * 1.0));
}
}
@@ -178,7 +227,7 @@ public class ReconfigureOnChangeTest {
ReconfigureOnChangeFilter rocf = new ReconfigureOnChangeFilter();
rocf.setContext(loggerContext);
File file = new File(SCAN1_FILE_AS_STR);
- ConfigurationWatchListUtil.updateWatchList(loggerContext, file.toURI().toURL());
+ ConfigurationWatchListUtil.setMainWatchURL(loggerContext, file.toURI().toURL());
rocf.start();
return rocf;
}
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 8f16313..afdcb0b 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
@@ -86,7 +86,7 @@ public abstract class GenericConfigurator extends ContextAwareBase {
}
protected void informContextOfURLUsedForConfiguration(URL url) {
- ConfigurationWatchListUtil.updateWatchList(context, url);
+ ConfigurationWatchListUtil.setMainWatchURL(context, url);
}
final public void doConfigure(InputStream inputStream) throws JoranException {
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java
index befbdc3..4e91506 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/IncludeAction.java
@@ -13,13 +13,16 @@
*/
package ch.qos.logback.core.joran.action;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
import java.util.List;
+import ch.qos.logback.core.joran.util.ConfigurationWatchListUtil;
import org.xml.sax.Attributes;
import ch.qos.logback.core.joran.event.SaxEvent;
@@ -41,7 +44,7 @@ public class IncludeAction extends Action {
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes)
- throws ActionException {
+ throws ActionException {
SaxEventRecorder recorder = new SaxEventRecorder();
@@ -105,7 +108,7 @@ public class IncludeAction extends Action {
return true;
}
throw new IllegalStateException("Count value [" + count
- + "] is not expected");
+ + "] is not expected");
}
private InputStream getInputStreamByFilePath(String pathToFile) {
@@ -118,15 +121,17 @@ public class IncludeAction extends Action {
}
}
- private InputStream getInputStreamByUrl(String urlAttribute) {
- URL url;
+ URL attributeToURL(String urlAttribute) {
try {
- url = new URL(urlAttribute);
+ return new URL(urlAttribute);
} catch (MalformedURLException mue) {
String errMsg = "URL [" + urlAttribute + "] is not well formed.";
addError(errMsg, mue);
return null;
}
+ }
+
+ private InputStream getInputStreamByUrl(URL url) {
return openURL(url);
}
@@ -140,38 +145,63 @@ public class IncludeAction extends Action {
}
}
- private InputStream getInputStreamByResource(String resourceAttribute) {
+ URL resourceAsURL(String resourceAttribute) {
URL url = Loader.getResourceBySelfClassLoader(resourceAttribute);
if (url == null) {
String errMsg = "Could not find resource corresponding to ["
- + resourceAttribute + "]";
+ + resourceAttribute + "]";
addError(errMsg);
return null;
+ } else
+ return url;
+ }
+
+ URL filePathAsURL(String path) {
+ URI uri = new File(path).toURI();
+ try {
+ return uri.toURL();
+ } catch (MalformedURLException e) {
+ // impossible to get here
+ e.printStackTrace();
+ return null;
}
+ }
+
+ private InputStream getInputStreamByResource(URL url) {
return openURL(url);
}
- InputStream getInputStream(InterpretationContext ec, Attributes attributes) {
+ URL getInputURL(InterpretationContext ec, Attributes attributes) {
String fileAttribute = attributes.getValue(FILE_ATTR);
String urlAttribute = attributes.getValue(URL_ATTR);
String resourceAttribute = attributes.getValue(RESOURCE_ATTR);
if (!OptionHelper.isEmpty(fileAttribute)) {
- attributeInUse = ec.subst(fileAttribute);
- return getInputStreamByFilePath(attributeInUse);
+ this.attributeInUse = ec.subst(fileAttribute);
+ return filePathAsURL(attributeInUse);
}
if (!OptionHelper.isEmpty(urlAttribute)) {
- attributeInUse = ec.subst(urlAttribute);
- return getInputStreamByUrl(attributeInUse);
+ this.attributeInUse = ec.subst(urlAttribute);
+ return attributeToURL(attributeInUse);
}
if (!OptionHelper.isEmpty(resourceAttribute)) {
- attributeInUse = ec.subst(resourceAttribute);
- return getInputStreamByResource(attributeInUse);
+ this.attributeInUse = ec.subst(resourceAttribute);
+ return resourceAsURL(attributeInUse);
}
// given previous checkAttributes() check we cannot reach this line
- throw new IllegalStateException("A input stream should have been returned");
+ throw new IllegalStateException("A URL stream should have been returned");
+
+ }
+
+ InputStream getInputStream(InterpretationContext ec, Attributes attributes) {
+ URL inputURL = getInputURL(ec, attributes);
+ if(inputURL == null)
+ return null;
+
+ ConfigurationWatchListUtil.addToWatchList(context, inputURL);
+ return openURL(inputURL);
}
private void trimHeadAndTail(SaxEventRecorder recorder) {
@@ -196,7 +226,7 @@ public class IncludeAction extends Action {
}
private void parseAndRecord(InputStream inputSource, SaxEventRecorder recorder)
- throws JoranException {
+ throws JoranException {
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 953f890..996058d 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,7 +37,7 @@ public class ConfigurationWatchList extends ContextAwareBase {
}
}
- void addToWatchList(URL url) {
+ public void addToWatchList(URL url) {
addAsFileToWatch(url);
}
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 278e5f4..44399e2 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
@@ -3,7 +3,15 @@ package ch.qos.logback.core.joran.util;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.joran.spi.ConfigurationWatchList;
+import ch.qos.logback.core.status.InfoStatus;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusManager;
+import ch.qos.logback.core.status.WarnStatus;
+import javax.security.auth.login.Configuration;
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URI;
import java.net.URL;
/**
@@ -11,10 +19,14 @@ import java.net.URL;
*/
public class ConfigurationWatchListUtil {
+ final static ConfigurationWatchListUtil origin = new ConfigurationWatchListUtil();
- public static void updateWatchList(Context context, URL url) {
+ private ConfigurationWatchListUtil() {
+ }
+
+ public static void setMainWatchURL(Context context, URL url) {
ConfigurationWatchList cwl = getConfigurationWatchList(context);
- if(cwl == null) {
+ if (cwl == null) {
cwl = new ConfigurationWatchList();
cwl.setContext(context);
context.putObject(CoreConstants.CONFIGURATION_WATCH_LIST, cwl);
@@ -24,7 +36,35 @@ public class ConfigurationWatchListUtil {
cwl.setMainURL(url);
}
- public static ConfigurationWatchList getConfigurationWatchList(Context context) {
- return (ConfigurationWatchList) context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST);
+ public static void addToWatchList(Context context, URL url) {
+ ConfigurationWatchList cwl = getConfigurationWatchList(context);
+ if (cwl == null) {
+ addWarn(context, "Null ConfigurationWatchList. Cannot add " + url);
+ } else {
+ addInfo(context, "Adding [" + url + "] to configuration watch list.");
+ cwl.addToWatchList(url);
+ }
+ }
+
+ public static ConfigurationWatchList getConfigurationWatchList(Context context) {
+ return (ConfigurationWatchList) context.getObject(CoreConstants.CONFIGURATION_WATCH_LIST);
+ }
+
+ static void addStatus(Context context, Status s) {
+ if (context == null) {
+ System.out.println("Null context in " + ConfigurationWatchList.class.getName());
+ return;
+ }
+ StatusManager sm = context.getStatusManager();
+ if (sm == null) return;
+ sm.add(s);
+ }
+
+ static void addInfo(Context context, String msg) {
+ addStatus(context, new InfoStatus(msg, origin));
+ }
+
+ static void addWarn(Context context, String msg) {
+ addStatus(context, new WarnStatus(msg, origin));
}
}
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index fd6ee67..af19296 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -60,6 +60,10 @@
href="manual/appenders.html#uniquelyNamed"><code><timestamp></code></a>
element in configuration files.</p>
+ <p>Logback can now scan for included files as well. This solves <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-245">LBCLASSIC-245</a>.
+ </p>
+
<hr width="80%" align="center" />
<h3>December 22nd, 2010 - Release of version 0.9.27</h3>
-----------------------------------------------------------------------
Summary of changes:
.../classic/gaffer/GafferConfigurator.groovy | 2 +-
.../src/test/input/turbo/scan_lbclassic154.xml | 2 -
.../classic/turbo/ReconfigureOnChangeTest.java | 91 +++++++++++++++-----
.../logback/core/joran/GenericConfigurator.java | 2 +-
.../logback/core/joran/action/IncludeAction.java | 62 ++++++++++----
.../core/joran/spi/ConfigurationWatchList.java | 2 +-
.../joran/util/ConfigurationWatchListUtil.java | 48 ++++++++++-
logback-site/src/site/pages/news.html | 4 +
8 files changed, 167 insertions(+), 46 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list