[logback-dev] svn commit: r1740 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/util logback-classic/src/test/java/ch/qos/logback/classic/joran logback-core/src/main/java/ch/qos/logback/core/status logback-core/src/main/java/ch/qos/logback/core/util logback-core/src/test/input/joran logback-core/src/test/java/ch/qos/logback/core/joran logback-core/src/test/java/ch/qos/logback/core/status
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Thu Aug 7 15:37:26 CEST 2008
Author: ceki
Date: Thu Aug 7 15:37:26 2008
New Revision: 1740
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java
logback/trunk/logback-core/src/test/input/joran/illformed.xml
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/status/TrivialStatusListener.java
- copied, changed from r1739, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/TrivialStatusListener.java
Removed:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/TrivialStatusListener.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java
Log:
Relates to LBCLASSIC-59 LBCLASSIC-58
- Setting the logback.statusListenerClass system property to the name of a StatusListener
class will automatically instantiate an instance of that class and register will the
StatusManager currently in use by the logger context. By convention, SYSOUT represents
a shorthand for ch.qos.logback.core.status.OnConsoleStatusListener
- documentation to follow
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/util/ContextInitializer.java Thu Aug 7 15:37:26 2008
@@ -59,6 +59,8 @@
public static void autoConfig(LoggerContext loggerContext,
ClassLoader classLoader) throws JoranException {
+ StatusListenerConfigHelper.installIfAsked(loggerContext);
+
URL url = findConfigFileURLFromSystemProperties(classLoader);
if (url == null) {
url = Loader.getResource(TEST_AUTOCONFIG_FILE, classLoader);
@@ -77,6 +79,7 @@
throws JoranException {
ClassLoader tccl = Loader.getTCL();
autoConfig(loggerContext, tccl);
-
}
+
+
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/status/OnConsoleStatusListener.java Thu Aug 7 15:37:26 2008
@@ -0,0 +1,12 @@
+package ch.qos.logback.core.status;
+
+import ch.qos.logback.core.util.StatusPrinter;
+
+public class OnConsoleStatusListener implements StatusListener {
+
+ public void addStatusEvent(Status status) {
+ StringBuilder sb = new StringBuilder();
+ StatusPrinter.buildStr(sb, "", status);
+ System.out.println(sb);
+ }
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/util/StatusPrinter.java Thu Aug 7 15:37:26 2008
@@ -79,7 +79,7 @@
}
}
- private static void buildStr(StringBuilder sb, String indentation, Status s) {
+ public static void buildStr(StringBuilder sb, String indentation, Status s) {
String prefix;
if (s.hasChildren()) {
prefix = indentation + "+ ";
Added: logback/trunk/logback-core/src/test/input/joran/illformed.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/input/joran/illformed.xml Thu Aug 7 15:37:26 2008
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<x>
+ <inc increment="1">
+</x>
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java Thu Aug 7 15:37:26 2008
@@ -9,6 +9,7 @@
*/
package ch.qos.logback.core.joran;
+import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -18,7 +19,7 @@
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(SkippingInInterpreterTest.class);
- suite.addTestSuite(TrivialcConfiguratorTest.class);
+ suite.addTest(new JUnit4TestAdapter(TrivialcConfiguratorTest.class));
suite.addTest(ch.qos.logback.core.joran.action.PackageTest.suite());
suite.addTest(ch.qos.logback.core.joran.event.PackageTest.suite());
suite.addTest(ch.qos.logback.core.joran.spi.PackageTest.suite());
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java Thu Aug 7 15:37:26 2008
@@ -10,52 +10,81 @@
package ch.qos.logback.core.joran;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.util.HashMap;
-import junit.framework.TestCase;
+import org.junit.Test;
+
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.joran.action.Action;
import ch.qos.logback.core.joran.action.ext.IncAction;
import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.TrivialStatusListener;
import ch.qos.logback.core.util.Constants;
+import ch.qos.logback.core.util.StatusPrinter;
-public class TrivialcConfiguratorTest extends TestCase {
+public class TrivialcConfiguratorTest {
Context context = new ContextBase();
-
- public TrivialcConfiguratorTest(String arg0) {
- super(arg0);
- }
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
public void doTest(String filename) throws Exception {
HashMap<Pattern, Action> rulesMap = new HashMap<Pattern, Action>();
rulesMap.put(new Pattern("x/inc"), new IncAction());
TrivialConfigurator gc = new TrivialConfigurator(rulesMap);
-
+
gc.setContext(context);
- gc.doConfigure(Constants.TEST_DIR_PREFIX
- + "input/joran/"+ filename);
+ gc.doConfigure(Constants.TEST_DIR_PREFIX + "input/joran/" + filename);
}
-
- public void test() throws Exception {
+
+ @Test
+ public void smokeTezt() throws Exception {
int oldBeginCount = IncAction.beginCount;
int oldEndCount = IncAction.endCount;
int oldErrorCount = IncAction.errorCount;
doTest("inc.xml");
assertEquals(oldErrorCount, IncAction.errorCount);
- assertEquals(oldBeginCount+1, IncAction.beginCount);
- assertEquals(oldEndCount+1, IncAction.endCount);
+ assertEquals(oldBeginCount + 1, IncAction.beginCount);
+ assertEquals(oldEndCount + 1, IncAction.endCount);
}
+ @Test
+ public void teztInexistentFile() {
+ TrivialStatusListener tsl = new TrivialStatusListener();
+ String filename = "nothereBLAH.xml";
+ context.getStatusManager().add(tsl);
+ try {
+ doTest(filename);
+ } catch (Exception e) {
+ }
+ assertTrue(tsl.list.size() + " should be greater than or equal to 1",
+ tsl.list.size() >= 1);
+ Status s0 = tsl.list.get(0);
+ assertTrue(s0.getMessage().startsWith("Could not open [" + filename + "]"));
+ }
+
+ @Test
+ public void teztIllFormedXML() {
+ TrivialStatusListener tsl = new TrivialStatusListener();
+ String filename = "illformed.xml";
+ context.getStatusManager().add(tsl);
+ try {
+ doTest(filename);
+ } catch (Exception e) {
+ }
+ assertEquals(2, tsl.list.size());
+ Status s0 = tsl.list.get(0);
+ assertTrue(s0.getMessage().startsWith(
+ "Parsing fatal error on line 5 and column 3"));
+ Status s1 = tsl.list.get(1);
+ assertTrue(s1
+ .getMessage()
+ .startsWith(
+ "Problem parsing XML document. See previously reported errors. Abandoning all further processing."));
+ }
}
Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/status/TrivialStatusListener.java (from r1739, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/TrivialStatusListener.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/TrivialStatusListener.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/status/TrivialStatusListener.java Thu Aug 7 15:37:26 2008
@@ -1,4 +1,4 @@
-package ch.qos.logback.classic.joran;
+package ch.qos.logback.core.status;
import java.util.ArrayList;
import java.util.List;
@@ -8,7 +8,7 @@
public class TrivialStatusListener implements StatusListener {
- List<Status> list = new ArrayList<Status>();
+ public List<Status> list = new ArrayList<Status>();
public void addStatusEvent(Status status) {
list.add(status);
More information about the logback-dev
mailing list