[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v0.9.18-93-g499abbb
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Thu Mar 18 18:28:34 CET 2010
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 499abbba89771332844fa84262e77277f66e8932 (commit)
from 32d669a3ab35c87a919ca47712eaef295360a46e (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=499abbba89771332844fa84262e77277f66e8932
http://github.com/ceki/logback/commit/499abbba89771332844fa84262e77277f66e8932
commit 499abbba89771332844fa84262e77277f66e8932
Author: Ceki Gulcu <ceki at qos.ch>
Date: Thu Mar 18 18:27:08 2010 +0100
Making SiftingAppender relient againt zero nested appenders and more than one nested appender.
diff --git a/logback-access/src/main/java/ch/qos/logback/access/sift/SiftingJoranConfigurator.java b/logback-access/src/main/java/ch/qos/logback/access/sift/SiftingJoranConfigurator.java
index 0e0ca00..13d00cc 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/sift/SiftingJoranConfigurator.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/sift/SiftingJoranConfigurator.java
@@ -25,21 +25,22 @@ import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.sift.SiftingJoranConfiguratorBase;
-public class SiftingJoranConfigurator extends SiftingJoranConfiguratorBase<AccessEvent> {
+public class SiftingJoranConfigurator extends
+ SiftingJoranConfiguratorBase<AccessEvent> {
String key;
String value;
-
+
SiftingJoranConfigurator(String key, String value) {
this.key = key;
this.value = value;
}
-
+
@Override
protected Pattern initialPattern() {
return new Pattern("configuration");
}
-
+
@Override
protected void addInstanceRules(RuleStore rs) {
rs.addRule(new Pattern("configuration/appender"), new AppenderAction());
@@ -48,7 +49,8 @@ public class SiftingJoranConfigurator extends SiftingJoranConfiguratorBase<Acce
@Override
protected void buildInterpreter() {
super.buildInterpreter();
- Map<String, Object> omap = interpreter.getInterpretationContext().getObjectMap();
+ Map<String, Object> omap = interpreter.getInterpretationContext()
+ .getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
omap.put(ActionConst.FILTER_CHAIN_BAG, new HashMap());
Map<String, String> propertiesMap = new HashMap<String, String>();
@@ -58,9 +60,14 @@ public class SiftingJoranConfigurator extends SiftingJoranConfiguratorBase<Acce
@SuppressWarnings("unchecked")
public Appender<AccessEvent> getAppender() {
- Map<String, Object> omap = interpreter.getInterpretationContext().getObjectMap();
- HashMap map = (HashMap) omap.get(ActionConst.APPENDER_BAG);
- Collection values = map.values();
+ Map<String, Object> omap = interpreter.getInterpretationContext()
+ .getObjectMap();
+ HashMap appenderMap = (HashMap) omap.get(ActionConst.APPENDER_BAG);
+ oneAndOnlyOneCheck(appenderMap);
+ Collection values = appenderMap.values();
+ if(values.size() == 0) {
+ return null;
+ }
return (Appender<AccessEvent>) values.iterator().next();
}
}
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/sift/SiftingJoranConfigurator.java b/logback-classic/src/main/java/ch/qos/logback/classic/sift/SiftingJoranConfigurator.java
index 66309cb..d831f41 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/sift/SiftingJoranConfigurator.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/sift/SiftingJoranConfigurator.java
@@ -68,8 +68,12 @@ public class SiftingJoranConfigurator extends SiftingJoranConfiguratorBase<ILog
@SuppressWarnings("unchecked")
public Appender<ILoggingEvent> getAppender() {
Map<String, Object> omap = interpreter.getInterpretationContext().getObjectMap();
- HashMap map = (HashMap) omap.get(ActionConst.APPENDER_BAG);
- Collection values = map.values();
+ HashMap appenderMap = (HashMap) omap.get(ActionConst.APPENDER_BAG);
+ oneAndOnlyOneCheck(appenderMap);
+ Collection values = appenderMap.values();
+ if(values.size() == 0) {
+ return null;
+ }
return (Appender<ILoggingEvent>) values.iterator().next();
}
}
diff --git a/logback-classic/src/test/input/joran/sift/multipleNesting.xml b/logback-classic/src/test/input/joran/sift/multipleNesting.xml
new file mode 100644
index 0000000..2dccd19
--- /dev/null
+++ b/logback-classic/src/test/input/joran/sift/multipleNesting.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration>
+
+<configuration debug="true">
+
+ <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
+
+ <discriminator>
+ <Key>userid</Key>
+ <defaultValue>smoke</defaultValue>
+ </discriminator>
+ <sift>
+ <appender name="a-${userid}"
+ class="ch.qos.logback.core.read.ListAppender" />
+ <appender name="b-${userid}"
+ class="ch.qos.logback.core.read.ListAppender" />
+ </sift>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="SIFT" />
+ </root>
+
+</configuration>
diff --git a/logback-classic/src/test/input/joran/sift/zeroNesting.xml b/logback-classic/src/test/input/joran/sift/zeroNesting.xml
new file mode 100644
index 0000000..5194291
--- /dev/null
+++ b/logback-classic/src/test/input/joran/sift/zeroNesting.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE configuration>
+
+<configuration debug="true">
+
+ <appender name="SIFT" class="ch.qos.logback.classic.sift.SiftingAppender">
+
+ <discriminator>
+ <Key>userid</Key>
+ <defaultValue>smoke</defaultValue>
+ </discriminator>
+ <sift>
+ </sift>
+ </appender>
+
+ <root level="DEBUG">
+ <appender-ref ref="SIFT" />
+ </root>
+
+</configuration>
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java
index 89608a3..c6723de 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/LoggerPerfTest.java
@@ -23,7 +23,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.turbo.NOPTurboFilter;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
-import ch.qos.logback.core.appender.NOPAppender;
+import ch.qos.logback.core.helpers.NOPAppender;
import ch.qos.logback.core.testUtil.Env;
public class LoggerPerfTest {
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/sift/SiftingAppenderTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/sift/SiftingAppenderTest.java
index b7ce5da..4bf89ac 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/sift/SiftingAppenderTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/sift/SiftingAppenderTest.java
@@ -16,6 +16,7 @@ package ch.qos.logback.classic.sift;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -29,9 +30,12 @@ import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.helpers.NOPAppender;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.read.ListAppender;
import ch.qos.logback.core.sift.AppenderTracker;
+import ch.qos.logback.core.status.ErrorStatus;
+import ch.qos.logback.core.status.StatusChecker;
import ch.qos.logback.core.testUtil.StringListAppender;
import ch.qos.logback.core.util.StatusPrinter;
@@ -65,8 +69,6 @@ public class SiftingAppenderTest {
SiftingAppender ha = (SiftingAppender) root.getAppender("SIFT");
ListAppender<ILoggingEvent> listAppender = (ListAppender<ILoggingEvent>) ha
.getAppenderTracker().get("smoke", timestamp);
-
- StatusPrinter.print(loggerContext);
assertNotNull(listAppender);
List<ILoggingEvent> eventList = listAppender.list;
assertEquals(1, listAppender.list.size());
@@ -74,6 +76,49 @@ public class SiftingAppenderTest {
}
@Test
+ public void zeroNesting() throws JoranException {
+ configure(PREFIX + "zeroNesting.xml");
+ logger.debug("hello");
+ logger.debug("hello");
+ logger.debug("hello");
+ logger.debug("hello");
+ logger.debug("hello");
+
+ long timestamp = 0;
+
+ SiftingAppender sa = (SiftingAppender) root.getAppender("SIFT");
+ NOPAppender<ILoggingEvent> nopa = (NOPAppender<ILoggingEvent>) sa
+ .getAppenderTracker().get("smoke", timestamp);
+ StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
+
+ assertNotNull(nopa);
+ StatusChecker sc = new StatusChecker(loggerContext);
+ assertTrue(sc.containsMatch(ErrorStatus.ERROR, "No nested appenders found"));
+ assertTrue(sc.containsMatch(ErrorStatus.ERROR,
+ "Failed to build an appender for discriminating value \\[smoke\\]"));
+ }
+
+ @Test
+ public void multipleNesting() throws JoranException {
+ configure(PREFIX + "multipleNesting.xml");
+ logger.debug("hello");
+ logger.debug("hello");
+ logger.debug("hello");
+
+ long timestamp = 0;
+
+ SiftingAppender sa = (SiftingAppender) root.getAppender("SIFT");
+ ListAppender<ILoggingEvent> listAppender = (ListAppender<ILoggingEvent>) sa
+ .getAppenderTracker().get("smoke", timestamp);
+ StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
+
+ assertNotNull(listAppender);
+ StatusChecker sc = new StatusChecker(loggerContext);
+ assertTrue(sc.containsMatch(ErrorStatus.ERROR,
+ "Only and only one appender can be nested"));
+ }
+
+ @Test
public void defaultLayoutRule() throws JoranException {
configure(PREFIX + "defaultLayoutRule.xml");
logger.debug("hello");
@@ -82,7 +127,6 @@ public class SiftingAppenderTest {
StringListAppender<ILoggingEvent> listAppender = (StringListAppender<ILoggingEvent>) ha
.getAppenderTracker().get("default", timestamp);
- StatusPrinter.print(loggerContext);
assertNotNull(listAppender);
List<String> strList = listAppender.strList;
assertEquals(1, strList.size());
@@ -99,8 +143,6 @@ public class SiftingAppenderTest {
SiftingAppender ha = (SiftingAppender) root.getAppender("SIFT");
ListAppender<ILoggingEvent> listAppender = (ListAppender<ILoggingEvent>) ha
.getAppenderTracker().get("a", timestamp);
- StatusPrinter.print(loggerContext);
-
assertNotNull(listAppender);
List<ILoggingEvent> eventList = listAppender.list;
assertEquals(1, listAppender.list.size());
@@ -115,4 +157,5 @@ public class SiftingAppenderTest {
assertEquals(1, ha.getAppenderTracker().keyList().size());
assertEquals("cycleDefault", ha.getAppenderTracker().keyList().get(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 637a1b4..699483f 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
@@ -92,7 +92,7 @@ public class CoreConstants {
public static long REFERENCE_BIPS = 9000;
- // maximum error acoutn to report
+ // the max number of times an error should be reported
static public final int MAX_ERROR_COUNT = 4;
diff --git a/logback-core/src/test/java/ch/qos/logback/core/appender/NOPAppender.java b/logback-core/src/main/java/ch/qos/logback/core/helpers/NOPAppender.java
similarity index 94%
rename from logback-core/src/test/java/ch/qos/logback/core/appender/NOPAppender.java
rename to logback-core/src/main/java/ch/qos/logback/core/helpers/NOPAppender.java
index 52b4003..5fb5129 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/appender/NOPAppender.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/helpers/NOPAppender.java
@@ -11,7 +11,7 @@
* 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.appender;
+package ch.qos.logback.core.helpers;
import ch.qos.logback.core.AppenderBase;
diff --git a/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java b/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java
index 7604a5f..5c7a6a4 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/joran/action/AppenderAction.java
@@ -102,8 +102,6 @@ public class AppenderAction<E> extends Action {
addWarn("The object at the of the stack is not the appender named ["
+ appender.getName() + "] pushed earlier.");
} else {
- addInfo("Popping appender named [" + appender.getName()
- + "] from the object stack");
ec.popObject();
}
}
diff --git a/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingAppenderBase.java b/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingAppenderBase.java
index dbfe217..c82ed9b 100644
--- a/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingAppenderBase.java
+++ b/logback-core/src/main/java/ch/qos/logback/core/sift/SiftingAppenderBase.java
@@ -14,7 +14,9 @@
package ch.qos.logback.core.sift;
import ch.qos.logback.core.Appender;
+import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.UnsynchronizedAppenderBase;
+import ch.qos.logback.core.helpers.NOPAppender;
import ch.qos.logback.core.joran.spi.JoranException;
/**
@@ -77,9 +79,11 @@ public abstract class SiftingAppenderBase<E> extends
if (appender == null) {
try {
appender = appenderFactory.buildAppender(context, discriminatingValue);
- if (appender != null) {
- appenderTracker.put(discriminatingValue, appender, timestamp);
+ if (appender == null) {
+ appender = buildNOPAppender(discriminatingValue);
}
+ appenderTracker.put(discriminatingValue, appender, timestamp);
+
} catch (JoranException e) {
addError("Failed to build appender for [" + discriminatingValue + "]",
e);
@@ -97,6 +101,18 @@ public abstract class SiftingAppenderBase<E> extends
public void setDiscriminator(Discriminator<E> discriminator) {
this.discriminator = discriminator;
}
+
+
+ int nopaWarningCount = 0;
+
+ NOPAppender<E> buildNOPAppender(String discriminatingValue) {
+ NOPAppender<E> nopa = new NOPAppender<E>();
+ if(nopaWarningCount < CoreConstants.MAX_ERROR_COUNT) {
+ nopaWarningCount++;
+ addError("Failed to build an appender for discriminating value ["+discriminatingValue+"]");
+ }
+ return nopa;
+ }
// sometime one needs to close a nested appender immediately
// for example when executing a command which has its own nested appender
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 0524f33..7d5c96e 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,24 +13,50 @@
*/
package ch.qos.logback.core.sift;
+import java.util.Map;
+
import ch.qos.logback.core.Appender;
+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.spi.Interpreter;
-public abstract class SiftingJoranConfiguratorBase<E> extends GenericConfigurator {
+public abstract class SiftingJoranConfiguratorBase<E> extends
+ GenericConfigurator {
+
+ final static String ONE_AND_ONLY_ONE_URL = CoreConstants.CODES_URL
+ + "#1andOnly1";
@Override
protected void addImplicitRules(Interpreter interpreter) {
NestedComplexPropertyIA nestedComplexIA = new NestedComplexPropertyIA();
nestedComplexIA.setContext(context);
interpreter.addImplicitAction(nestedComplexIA);
-
+
NestedBasicPropertyIA nestedSimpleIA = new NestedBasicPropertyIA();
nestedSimpleIA.setContext(context);
interpreter.addImplicitAction(nestedSimpleIA);
}
-
+
abstract public Appender<E> getAppender();
+
+ int errorEmmissionCount = 0;
+
+ protected void oneAndOnlyOneCheck(Map appenderMap) {
+ String errMsg = null;
+ if (appenderMap.size() == 0) {
+ errorEmmissionCount++;
+ errMsg = "No nested appenders found within the <sift> element in SiftingAppender.";
+ } else if (appenderMap.size() > 1) {
+ errorEmmissionCount++;
+ errMsg = "Only and only one appender can be nested the <sift> element in SiftingAppender. See also "
+ + ONE_AND_ONLY_ONE_URL;
+ }
+
+ if (errMsg != null && errorEmmissionCount < CoreConstants.MAX_ERROR_COUNT) {
+ addError(errMsg);
+ }
+
+ }
}
diff --git a/logback-core/src/test/java/ch/qos/logback/core/sift/Simulator.java b/logback-core/src/test/java/ch/qos/logback/core/sift/Simulator.java
index db91d02..40bdf11 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/sift/Simulator.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/sift/Simulator.java
@@ -20,7 +20,7 @@ import java.util.Map;
import java.util.Random;
import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.appender.NOPAppender;
+import ch.qos.logback.core.helpers.NOPAppender;
import ch.qos.logback.core.sift.tracker.AppenderTrackerTImpl;
import ch.qos.logback.core.sift.tracker.SimulationEvent;
import ch.qos.logback.core.sift.tracker.SimulationEvent.SimEventType;
diff --git a/logback-core/src/test/java/ch/qos/logback/core/spi/AppenderAttachableImplTest.java b/logback-core/src/test/java/ch/qos/logback/core/spi/AppenderAttachableImplTest.java
index 300fedd..05b3a4d 100644
--- a/logback-core/src/test/java/ch/qos/logback/core/spi/AppenderAttachableImplTest.java
+++ b/logback-core/src/test/java/ch/qos/logback/core/spi/AppenderAttachableImplTest.java
@@ -26,7 +26,7 @@ import org.junit.Before;
import org.junit.Test;
import ch.qos.logback.core.Appender;
-import ch.qos.logback.core.appender.NOPAppender;
+import ch.qos.logback.core.helpers.NOPAppender;
/**
* This test case verifies all the methods of AppenderAttableImpl work properly.
diff --git a/logback-site/src/site/pages/codes.html b/logback-site/src/site/pages/codes.html
index 93c98de..3ab510d 100644
--- a/logback-site/src/site/pages/codes.html
+++ b/logback-site/src/site/pages/codes.html
@@ -354,6 +354,7 @@
<hr />
+ <!-- ============================================================= -->
<p><a name="syslog_layout" href="#syslog_layout"> SyslogAppender
does not admit a layout.</a>
</p>
@@ -371,9 +372,19 @@
</p>
<hr/>
+
+ <!-- ============================================================= -->
+ <p><a name="1andOnly1" href="#1andOnly1">Only and only one appender
+ can be nested the <sift> element in
+ <code>SiftingAppender</code>.</a>
+ </p>
+ <p>SiftingAppender admits one and only one nested appender.
+ </p>
+
+ <hr/>
- <script src="templates/footer.js" type="text/javascript"></script>
+ <script src="templates/footer.js" type="text/javascript"></script>
</div>
</body>
</html>
-----------------------------------------------------------------------
Summary of changes:
.../access/sift/SiftingJoranConfigurator.java | 23 ++++++---
.../classic/sift/SiftingJoranConfigurator.java | 8 ++-
.../joran/sift/{smoke.xml => multipleNesting.xml} | 4 +-
.../joran/sift/{smoke.xml => zeroNesting.xml} | 4 +-
.../ch/qos/logback/classic/LoggerPerfTest.java | 2 +-
.../logback/classic/sift/SiftingAppenderTest.java | 53 ++++++++++++++++++--
.../java/ch/qos/logback/core/CoreConstants.java | 2 +-
.../ch/qos/logback/core/helpers}/NOPAppender.java | 2 +-
.../logback/core/joran/action/AppenderAction.java | 2 -
.../qos/logback/core/sift/SiftingAppenderBase.java | 20 +++++++-
.../core/sift/SiftingJoranConfiguratorBase.java | 32 +++++++++++-
.../java/ch/qos/logback/core/sift/Simulator.java | 2 +-
.../core/spi/AppenderAttachableImplTest.java | 2 +-
logback-site/src/site/pages/codes.html | 13 +++++-
14 files changed, 137 insertions(+), 32 deletions(-)
copy logback-classic/src/test/input/joran/sift/{smoke.xml => multipleNesting.xml} (78%)
copy logback-classic/src/test/input/joran/sift/{smoke.xml => zeroNesting.xml} (78%)
rename logback-core/src/{test/java/ch/qos/logback/core/appender => main/java/ch/qos/logback/core/helpers}/NOPAppender.java (94%)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list