logback-dev
Threads by month
- ----- 2025 -----
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
October 2006
- 6 participants
- 258 discussions

svn commit: r688 - logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net
by noreply.ceki@qos.ch 16 Oct '06
by noreply.ceki@qos.ch 16 Oct '06
16 Oct '06
Author: ceki
Date: Mon Oct 16 08:31:22 2006
New Revision: 688
Modified:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/LoggingEventSerializationTest.java
Log:
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/LoggingEventSerializationTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/LoggingEventSerializationTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/net/LoggingEventSerializationTest.java Mon Oct 16 08:31:22 2006
@@ -118,7 +118,8 @@
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
inputStream = new ObjectInputStream(bis);
- LoggingEvent remoteEvent1 = (LoggingEvent) inputStream.readObject();
+ // skip over one object
+ inputStream.readObject();
LoggingEvent remoteEvent2 = (LoggingEvent) inputStream.readObject();
// We observe the second logging event. It should provide us with
1
0

svn commit: r687 - logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat
by noreply.ceki@qos.ch 16 Oct '06
by noreply.ceki@qos.ch 16 Oct '06
16 Oct '06
Author: ceki
Date: Mon Oct 16 08:28:45 2006
New Revision: 687
Modified:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
Log:
Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java (original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java Mon Oct 16 08:28:45 2006
@@ -18,6 +18,7 @@
import ch.qos.logback.core.BasicStatusManager;
import ch.qos.logback.core.Context;
import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.spi.AppenderAttachable;
import ch.qos.logback.core.spi.AppenderAttachableImpl;
import ch.qos.logback.core.spi.FilterAttachableImpl;
@@ -48,15 +49,15 @@
* Here is a sample logback.xml file that can be used right away:
*
* <pre>
- * <configuration>
- * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- * <layout class="ch.qos.logback.access.PatternLayout">
- * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL " />
- * </layout>
- * </appender>
- *
- * <appender-ref ref="STDOUT" />
- * </configuration>
+ * <configuration>
+ * <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ * <layout class="ch.qos.logback.access.PatternLayout">
+ * <param name="Pattern" value="%date %server %remoteIP %clientHost %user %requestURL " />
+ * </layout>
+ * </appender>
+ *
+ * <appender-ref ref="STDOUT" />
+ * </configuration>
* </pre>
*
* A special, module-specific implementation of PatternLayout was implemented to
@@ -110,10 +111,13 @@
}
File configFile = new File(filename);
if (configFile.exists()) {
- JoranConfigurator jc = new JoranConfigurator();
- jc.setContext(this);
- jc.doConfigure(filename);
- StatusPrinter.print(getStatusManager());
+ try {
+ JoranConfigurator jc = new JoranConfigurator();
+ jc.setContext(this);
+ jc.doConfigure(filename);
+ } catch (JoranException e) {
+ StatusPrinter.print(getStatusManager());
+ }
} else {
getStatusManager().add(
new ErrorStatus("[" + filename + "] does not exist", this));
1
0

svn commit: r686 - in logback/trunk/logback-core/src: main/java/ch/qos/logback/core/joran test/input/joran test/java/ch/qos/logback/core/joran test/java/ch/qos/logback/core/joran/action test/java/ch/qos/logback/core/joran/spi
by noreply.ceki@qos.ch 16 Oct '06
by noreply.ceki@qos.ch 16 Oct '06
16 Oct '06
Author: ceki
Date: Mon Oct 16 08:28:17 2006
New Revision: 686
Modified:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
logback/trunk/logback-core/src/test/input/joran/inc.xml
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.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/SkippingInInterpreterTest.java
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/action/BadBeginAction.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
Log:
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java Mon Oct 16 08:28:17 2006
@@ -1,3 +1,13 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
package ch.qos.logback.core.joran;
import java.io.File;
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -10,16 +10,10 @@
package ch.qos.logback.core.joran;
-import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
-import org.xml.sax.InputSource;
-
import ch.qos.logback.core.joran.action.ActionConst;
import ch.qos.logback.core.joran.action.AppenderAction;
import ch.qos.logback.core.joran.action.AppenderRefAction;
@@ -51,40 +45,6 @@
abstract public class JoranConfiguratorBase extends GenericConfigurator {
- final public void xdoConfigure(final InputSource inputSource) {
- // This line is needed here because there is logging from inside this
- // method.
- buildInterpreter();
-
- ExecutionContext ec = interpreter.getExecutionContext();
-
- SAXParser saxParser = null;
- try {
- SAXParserFactory spf = SAXParserFactory.newInstance();
- spf.setValidating(false);
- spf.setNamespaceAware(true);
- saxParser = spf.newSAXParser();
- } catch (Exception pce) {
- String errMsg = "Parser configuration error occured";
- ec.addError(errMsg, pce);
- return;
- }
-
- try {
- // attachListAppender(context);
- saxParser.parse(inputSource, interpreter);
- } catch (IOException ie) {
- final String errMsg = "I/O error occurred while parsing xml file";
- ec.addError(errMsg, ie);
- } catch (Exception ex) {
- final String errMsg = "Problem parsing XML document. See previously reported errors. Abandoning all further processing.";
- addError(errMsg, ex);
- return;
- } finally {
- // detachListAppender(repository);
- }
- }
-
public List getErrorList() {
return null;
}
Modified: logback/trunk/logback-core/src/test/input/joran/inc.xml
==============================================================================
--- logback/trunk/logback-core/src/test/input/joran/inc.xml (original)
+++ logback/trunk/logback-core/src/test/input/joran/inc.xml Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<x>
- <inc/>
+ <inc increment="1"/>
</x>
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -18,18 +18,21 @@
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
+
+import org.xml.sax.Attributes;
+
import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
import ch.qos.logback.core.joran.spi.BodyEvent;
import ch.qos.logback.core.joran.spi.SaxEvent;
import ch.qos.logback.core.joran.spi.SaxEventRecorder;
+import ch.qos.logback.core.joran.spi.StartEvent;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.util.Constants;
/**
- * Test the way Interpreter skips elements in case of exceptions thrown by
- * Actions.
+ * Test whether SaxEventRecorder does a good job.
*
* @author Ceki Gulcu
*/
@@ -92,13 +95,26 @@
List<SaxEvent> seList = doTest("ampEvent.xml");
StatusManager sm = context.getStatusManager();
assertTrue(sm.getLevel() == Status.INFO);
- dump(seList);
+ //dump(seList);
assertEquals(3, seList.size());
BodyEvent be = (BodyEvent) seList.get(1);
assertEquals("xxx & yyy", be.getText());
}
+ public void test3() throws Exception {
+ List<SaxEvent> seList = doTest("inc.xml");
+ StatusManager sm = context.getStatusManager();
+ assertTrue(sm.getLevel() == Status.INFO);
+ //dump(seList);
+ assertEquals(4, seList.size());
+
+ StartEvent se = (StartEvent) seList.get(1);
+ Attributes attr = se.getAttributes();
+ assertNotNull(attr);
+ assertEquals("1", attr.getValue("increment"));
+ }
+
public static Test XXXsuite() {
TestSuite suite = new TestSuite();
suite.addTest(new EventRecorderTest("test2"));
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 Mon Oct 16 08:28:17 2006
@@ -1,3 +1,13 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
package ch.qos.logback.core.joran;
import junit.framework.Test;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/SkippingInInterpreterTest.java Mon Oct 16 08:28:17 2006
@@ -98,7 +98,8 @@
Interpreter jp = new Interpreter(rs);
ExecutionContext ec = jp.getExecutionContext();
-
+ ec.setContext(new ContextBase());
+
SAXParser saxParser = createParser();
saxParser.parse("file:" + Constants.TEST_DIR_PREFIX + "input/joran/badEnd1.xml", jp);
@@ -118,7 +119,8 @@
Interpreter jp = new Interpreter(rs);
ExecutionContext ec = jp.getExecutionContext();
-
+ ec.setContext(new ContextBase());
+
SAXParser saxParser = createParser();
saxParser.parse("file:" + Constants.TEST_DIR_PREFIX + "input/joran/badEnd2.xml", jp);
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 Mon Oct 16 08:28:17 2006
@@ -33,10 +33,11 @@
public void test() 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);
-
}
}
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadBeginAction.java Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/BadEndAction.java Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -7,7 +7,6 @@
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation.
*/
-
package ch.qos.logback.core.joran.action;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/HelloAction.java Mon Oct 16 08:28:17 2006
@@ -1,5 +1,5 @@
/**
- * LOGBack: the generic, reliable, fast and flexible logging framework.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
* Copyright (C) 1999-2006, QOS.ch
*
@@ -7,7 +7,6 @@
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation.
*/
-
package ch.qos.logback.core.joran.action;
import org.xml.sax.Attributes;
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java Mon Oct 16 08:28:17 2006
@@ -13,6 +13,7 @@
import org.xml.sax.Attributes;
import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.ActionException;
import ch.qos.logback.core.joran.spi.ExecutionContext;
@@ -21,14 +22,20 @@
static public int beginCount;
static public int endCount;
+ static public int errorCount;
/**
* Instantiates an layout of the given class and sets its name.
*
*/
- public void begin(ExecutionContext ec, String name, Attributes attributes) {
- System.out.println("IncAction Begin called");
+ public void begin(ExecutionContext ec, String name, Attributes attributes) throws ActionException {
+ //System.out.println("IncAction Begin called");
beginCount++;
+ String val = attributes.getValue("increment");
+ if(!"1".equals(val)) {
+ errorCount++;
+ throw new ActionException(ActionException.SKIP_SIBLINGS);
+ }
}
/**
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/spi/PackageTest.java Mon Oct 16 08:28:17 2006
@@ -9,15 +9,13 @@
*/
package ch.qos.logback.core.joran.spi;
-
-
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class PackageTest extends TestCase {
- public static Test suite() {
+ public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(PatternTest.class);
suite.addTestSuite(SimpleStoreTest.class);
1
0

svn commit: r685 - in logback/trunk/logback-access: . src/main/java/ch/qos/logback/access/resin
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 19:48:01 2006
New Revision: 685
Removed:
logback/trunk/logback-access/src/main/java/ch/qos/logback/access/resin/
Modified:
logback/trunk/logback-access/pom.xml
Log:
removing references to resin
Modified: logback/trunk/logback-access/pom.xml
==============================================================================
--- logback/trunk/logback-access/pom.xml (original)
+++ logback/trunk/logback-access/pom.xml Sun Oct 15 19:48:01 2006
@@ -57,12 +57,6 @@
</dependency>
<dependency>
- <groupId>com.caucho</groupId>
- <artifactId>resin</artifactId>
- <scope>compile</scope>
- </dependency>
-
- <dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>servlet-api-2.5</artifactId>
<scope>compile</scope>
1
0

svn commit: r684 - logback/trunk/logback-core/src/test/input/joran
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 19:45:07 2006
New Revision: 684
Added:
logback/trunk/logback-core/src/test/input/joran/inc.xml
Log:
added missing file
Added: logback/trunk/logback-core/src/test/input/joran/inc.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/input/joran/inc.xml Sun Oct 15 19:45:07 2006
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<x>
+ <inc/>
+</x>
1
0
Author: ceki
Date: Sun Oct 15 19:44:14 2006
New Revision: 683
Added:
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java
logback/trunk/logback-core/src/test/input/joran/ampEvent.xml
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java
- copied, changed from r678, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventInterpreterTest.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/TrivialConfigurator.java
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/action/IncAction.java
Removed:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventInterpreterTest.java
Modified:
logback/trunk/logback-classic/examples/src/chapter1/MyAppWithConfigFile.java
logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java
logback/trunk/logback-classic/examples/src/chapter5/CallerEvaluatorExample.java
logback/trunk/logback-classic/examples/src/chapter5/ExceptionEvaluatorExample.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketServer.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java
logback/trunk/logback-core/src/test/input/joran/event1.xml
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/AllTest.java
Log:
- joran now registers sax events and perform configration by replaying them
- fixed bug related to element text (see bug #12). If the element body contained
entities joran would not return the complete text part only parts of it.
- JoranConfigurator.doConfigure throws a JoranException. This changes has pros and
cons. On the plus side, it is a little for robust.
Modified: logback/trunk/logback-classic/examples/src/chapter1/MyAppWithConfigFile.java
==============================================================================
--- logback/trunk/logback-classic/examples/src/chapter1/MyAppWithConfigFile.java (original)
+++ logback/trunk/logback-classic/examples/src/chapter1/MyAppWithConfigFile.java Sun Oct 15 19:44:14 2006
@@ -6,23 +6,26 @@
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;
public class MyAppWithConfigFile {
-
- public static void main(String[] args) {
- Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
-
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
- logger.info("Entering application.");
- Bar bar = new Bar();
- bar.doIt();
- logger.info("Exiting application.");
-
- StatusPrinter.print(lc.getStatusManager());
- }
+ public static void main(String[] args) {
+ Logger logger = LoggerFactory.getLogger(MyAppWithConfigFile.class);
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc.getStatusManager());
+ }
+ logger.info("Entering application.");
+ Bar bar = new Bar();
+ bar.doIt();
+ logger.info("Exiting application.");
+
+ }
}
Modified: logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java
==============================================================================
--- logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java (original)
+++ logback/trunk/logback-classic/examples/src/chapter4/ConfigurationTester.java Sun Oct 15 19:44:14 2006
@@ -6,17 +6,21 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import chapter4.sub.sample.Bar;
+
/**
*
* This class can be used to check the result of a configuration file.
* <p>
- * When all the logback-core, logback-classic and their dependencies have been added
- * to the ClassPath, one can launch this class using the following command:
+ * When all the logback-core, logback-classic and their dependencies have been
+ * added to the ClassPath, one can launch this class using the following
+ * command:
* <p>
- * java chapter4.ConfigurationTester chapter4/conf/name_of_the_configuration_file.xml
- *
+ * java chapter4.ConfigurationTester
+ * chapter4/conf/name_of_the_configuration_file.xml
+ *
* @author Sébastien Pennec
*/
public class ConfigurationTester {
@@ -25,10 +29,13 @@
Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
-
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ je.printStackTrace();
+ }
logger.debug("**Hello {}", new Bar());
MDC.put("testKey", "testValueFromMDC");
MDC.put("testKey2", "value2");
Modified: logback/trunk/logback-classic/examples/src/chapter5/CallerEvaluatorExample.java
==============================================================================
--- logback/trunk/logback-classic/examples/src/chapter5/CallerEvaluatorExample.java (original)
+++ logback/trunk/logback-classic/examples/src/chapter5/CallerEvaluatorExample.java Sun Oct 15 19:44:14 2006
@@ -5,17 +5,24 @@
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;
public class CallerEvaluatorExample {
public static void main(String[] args) throws InterruptedException {
- Logger logger = (Logger) LoggerFactory.getLogger(CallerEvaluatorExample.class);
+ Logger logger = (Logger) LoggerFactory
+ .getLogger(CallerEvaluatorExample.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
-
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+
for (int i = 0; i < 5; i++) {
if (i == 3) {
logger.debug("stacktrace logging statement" + i);
Modified: logback/trunk/logback-classic/examples/src/chapter5/ExceptionEvaluatorExample.java
==============================================================================
--- logback/trunk/logback-classic/examples/src/chapter5/ExceptionEvaluatorExample.java (original)
+++ logback/trunk/logback-classic/examples/src/chapter5/ExceptionEvaluatorExample.java Sun Oct 15 19:44:14 2006
@@ -7,27 +7,33 @@
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;
public class ExceptionEvaluatorExample {
public static void main(String[] args) throws InterruptedException {
- Logger logger = (Logger) LoggerFactory.getLogger(ExceptionEvaluatorExample.class);
+ Logger logger = (Logger) LoggerFactory
+ .getLogger(ExceptionEvaluatorExample.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(args[0]);
-
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(args[0]);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
for (int i = 0; i < 5; i++) {
if (i == 3) {
Marker ignoreMarker = MarkerFactory.getMarker("IGNORE");
- logger.debug(ignoreMarker, "logging statement" + i, new Exception("test"));
+ logger.debug(ignoreMarker, "logging statement" + i, new Exception(
+ "test"));
} else {
logger.debug("logging statement" + i, new Exception("test"));
}
}
-
+
StatusPrinter.print(lc);
}
}
\ No newline at end of file
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/JoranConfigurator.java Sun Oct 15 19:44:14 2006
@@ -32,7 +32,9 @@
public JoranConfigurator() {
}
+ @Override
public void addInstanceRules(RuleStore rs) {
+ super.addInstanceRules(rs);
rs.addRule(new Pattern("configuration"), new ConfigurationAction());
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SimpleSocketServer.java Sun Oct 15 19:44:14 2006
@@ -17,22 +17,23 @@
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
+import ch.qos.logback.core.joran.spi.JoranException;
/**
* A simple {@link SocketNode} based server.
*
* <pre>
- * <b>Usage:</b> java ch.qos.logback.classic.net.SimpleSocketServer port configFile
- *
- * where
+ * <b>Usage:</b> java ch.qos.logback.classic.net.SimpleSocketServer port configFile
+ *
+ * where
* <em>
* port
* </em>
- * is a part number where the server listens and
+ * is a part number where the server listens and
* <em>
* configFile
* </em>
- * is an xml configuration file fed to {@link JoranConfigurator}.
+ * is an xml configuration file fed to {@link JoranConfigurator}.
* </pre>
*
* @author Ceki Gülcü
@@ -42,57 +43,57 @@
*/
public class SimpleSocketServer {
- static Logger logger = LoggerFactory.getLogger(SimpleSocketServer.class);
+ static Logger logger = LoggerFactory.getLogger(SimpleSocketServer.class);
- static int port;
+ static int port;
- public static void main(String argv[]) {
- if (argv.length == 2) {
- init(argv[0], argv[1]);
- } else {
- usage("Wrong number of arguments.");
- }
-
- runServer();
- }
-
- static void runServer() {
- try {
- logger.info("Listening on port " + port);
- ServerSocket serverSocket = new ServerSocket(port);
- while (true) {
- logger.info("Waiting to accept a new client.");
- Socket socket = serverSocket.accept();
- logger.info("Connected to client at " + socket.getInetAddress());
- logger.info("Starting new socket node.");
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- new Thread(new SocketNode(socket, lc)).start();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- static void usage(String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + SimpleSocketServer.class.getName()
- + " port configFile");
- System.exit(1);
- }
-
- static void init(String portStr, String configFile) {
- try {
- port = Integer.parseInt(portStr);
- } catch (java.lang.NumberFormatException e) {
- e.printStackTrace();
- usage("Could not interpret port number [" + portStr + "].");
- }
-
- if (configFile.endsWith(".xml")) {
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(configFile);
- }
- }
+ public static void main(String argv[]) throws Exception {
+ if (argv.length == 2) {
+ init(argv[0], argv[1]);
+ } else {
+ usage("Wrong number of arguments.");
+ }
+
+ runServer();
+ }
+
+ static void runServer() {
+ try {
+ logger.info("Listening on port " + port);
+ ServerSocket serverSocket = new ServerSocket(port);
+ while (true) {
+ logger.info("Waiting to accept a new client.");
+ Socket socket = serverSocket.accept();
+ logger.info("Connected to client at " + socket.getInetAddress());
+ logger.info("Starting new socket node.");
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ new Thread(new SocketNode(socket, lc)).start();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ static void usage(String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + SimpleSocketServer.class.getName()
+ + " port configFile");
+ System.exit(1);
+ }
+
+ static void init(String portStr, String configFile) throws JoranException {
+ try {
+ port = Integer.parseInt(portStr);
+ } catch (java.lang.NumberFormatException e) {
+ e.printStackTrace();
+ usage("Could not interpret port number [" + portStr + "].");
+ }
+
+ if (configFile.endsWith(".xml")) {
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(configFile);
+ }
+ }
}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketServer.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketServer.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/net/SocketServer.java Sun Oct 15 19:44:14 2006
@@ -21,17 +21,19 @@
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;
/**
* A {@link SocketNode} based server that uses a different hierarchy for each
* client.
*
* <pre>
- * <b>Usage:</b> java ch.qos.logback.classic.net.SocketServer port configFile configDir
- *
- * where <b>port</b> is a part number where the server listens,
- * <b>configFile</b> is an xml configuration file fed to the {@link JoranConfigurator} and
- * <b>configDir</b> is a path to a directory containing configuration files, possibly one for each client host.
+ * <b>Usage:</b> java ch.qos.logback.classic.net.SocketServer port configFile configDir
+ *
+ * where <b>port</b> is a part number where the server listens,
+ * <b>configFile</b> is an xml configuration file fed to the {@link JoranConfigurator} and
+ * <b>configDir</b> is a path to a directory containing configuration files, possibly one for each client host.
* </pre>
*
* <p>
@@ -72,132 +74,137 @@
*
*
* @author Ceki Gülcü
- *
- * @since 1.0
*/
public class SocketServer {
- static String GENERIC = "generic";
- static String CONFIG_FILE_EXT = ".lcf";
+ static String GENERIC = "generic";
+ static String CONFIG_FILE_EXT = ".lcf";
- static Logger logger = LoggerFactory.getLogger(SocketServer.class);
- static SocketServer server;
- static int port;
-
- // key=inetAddress, value=hierarchy
- Hashtable<InetAddress, LoggerContext> hierarchyMap;
- LoggerContext genericHierarchy;
- File dir;
-
- public static void main(String argv[]) {
- if (argv.length == 3) {
- init(argv[0], argv[1], argv[2]);
- } else {
- usage("Wrong number of arguments.");
- }
-
- try {
- logger.info("Listening on port " + port);
- ServerSocket serverSocket = new ServerSocket(port);
- while (true) {
- logger.info("Waiting to accept a new client.");
- Socket socket = serverSocket.accept();
- InetAddress inetAddress = socket.getInetAddress();
- logger.info("Connected to client at " + inetAddress);
-
- LoggerContext h = (LoggerContext) server.hierarchyMap.get(inetAddress);
- if (h == null) {
- h = server.configureHierarchy(inetAddress);
- }
-
- logger.info("Starting new socket node.");
- new Thread(new SocketNode(socket, h)).start();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- static void usage(String msg) {
- System.err.println(msg);
- System.err.println("Usage: java " + SocketServer.class.getName()
- + " port configFile directory");
- System.exit(1);
- }
-
- static void init(String portStr, String configFile, String dirStr) {
- try {
- port = Integer.parseInt(portStr);
- } catch (java.lang.NumberFormatException e) {
- e.printStackTrace();
- usage("Could not interpret port number [" + portStr + "].");
- }
-
- LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(configFile);
-
- File dir = new File(dirStr);
- if (!dir.isDirectory()) {
- usage("[" + dirStr + "] is not a directory.");
- }
- server = new SocketServer(dir);
- }
-
- public SocketServer(File directory) {
- this.dir = directory;
- hierarchyMap = new Hashtable<InetAddress, LoggerContext>(11);
- }
-
- // This method assumes that there is no hiearchy for inetAddress
- // yet. It will configure one and return it.
- LoggerContext configureHierarchy(InetAddress inetAddress) {
- logger.info("Locating configuration file for " + inetAddress);
- // We assume that the toSting method of InetAddress returns is in
- // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1
- String s = inetAddress.toString();
- int i = s.indexOf("/");
- if (i == -1) {
- logger.warn("Could not parse the inetAddress [" + inetAddress
- + "]. Using default hierarchy.");
- return genericHierarchy();
- } else {
- String key = s.substring(0, i);
-
- File configFile = new File(dir, key + CONFIG_FILE_EXT);
- if (configFile.exists()) {
- LoggerContext lc = new LoggerContext();
- hierarchyMap.put(inetAddress, lc);
-
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(lc);
- configurator.doConfigure(configFile);
-
- return lc;
- } else {
- logger.warn("Could not find config file [" + configFile + "].");
- return genericHierarchy();
- }
- }
- }
-
- LoggerContext genericHierarchy() {
- if (genericHierarchy == null) {
- File f = new File(dir, GENERIC + CONFIG_FILE_EXT);
- if (f.exists()) {
- genericHierarchy = new LoggerContext();
- JoranConfigurator configurator = new JoranConfigurator();
- configurator.setContext(genericHierarchy);
- configurator.doConfigure(f.getAbsolutePath());
-
- } else {
- logger.warn("Could not find config file [" + f
- + "]. Will use the default hierarchy.");
- genericHierarchy = new LoggerContext();
- }
- }
- return genericHierarchy;
- }
+ static Logger logger = LoggerFactory.getLogger(SocketServer.class);
+ static SocketServer server;
+ static int port;
+
+ // key=inetAddress, value=hierarchy
+ Hashtable<InetAddress, LoggerContext> hierarchyMap;
+ LoggerContext genericHierarchy;
+ File dir;
+
+ public static void main(String argv[]) throws Exception {
+ if (argv.length == 3) {
+ init(argv[0], argv[1], argv[2]);
+ } else {
+ usage("Wrong number of arguments.");
+ }
+
+ try {
+ logger.info("Listening on port " + port);
+ ServerSocket serverSocket = new ServerSocket(port);
+ while (true) {
+ logger.info("Waiting to accept a new client.");
+ Socket socket = serverSocket.accept();
+ InetAddress inetAddress = socket.getInetAddress();
+ logger.info("Connected to client at " + inetAddress);
+
+ LoggerContext h = (LoggerContext) server.hierarchyMap.get(inetAddress);
+ if (h == null) {
+ h = server.configureHierarchy(inetAddress);
+ }
+
+ logger.info("Starting new socket node.");
+ new Thread(new SocketNode(socket, h)).start();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ static void usage(String msg) {
+ System.err.println(msg);
+ System.err.println("Usage: java " + SocketServer.class.getName()
+ + " port configFile directory");
+ System.exit(1);
+ }
+
+ static void init(String portStr, String configFile, String dirStr)
+ throws JoranException {
+ try {
+ port = Integer.parseInt(portStr);
+ } catch (java.lang.NumberFormatException e) {
+ e.printStackTrace();
+ usage("Could not interpret port number [" + portStr + "].");
+ }
+
+ LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(configFile);
+
+ File dir = new File(dirStr);
+ if (!dir.isDirectory()) {
+ usage("[" + dirStr + "] is not a directory.");
+ }
+ server = new SocketServer(dir);
+ }
+
+ public SocketServer(File directory) {
+ this.dir = directory;
+ hierarchyMap = new Hashtable<InetAddress, LoggerContext>(11);
+ }
+
+ // This method assumes that there is no hiearchy for inetAddress
+ // yet. It will configure one and return it.
+ LoggerContext configureHierarchy(InetAddress inetAddress) {
+ logger.info("Locating configuration file for " + inetAddress);
+ // We assume that the toSting method of InetAddress returns is in
+ // the format hostname/d1.d2.d3.d4 e.g. torino/192.168.1.1
+ String s = inetAddress.toString();
+ int i = s.indexOf("/");
+ if (i == -1) {
+ logger.warn("Could not parse the inetAddress [" + inetAddress
+ + "]. Using default hierarchy.");
+ return genericHierarchy();
+ } else {
+ String key = s.substring(0, i);
+
+ File configFile = new File(dir, key + CONFIG_FILE_EXT);
+ if (configFile.exists()) {
+ LoggerContext lc = new LoggerContext();
+ hierarchyMap.put(inetAddress, lc);
+
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(lc);
+ configurator.doConfigure(configFile);
+ } catch (JoranException je) {
+ StatusPrinter.print(lc);
+ }
+ return lc;
+ } else {
+ logger.warn("Could not find config file [" + configFile + "].");
+ return genericHierarchy();
+ }
+ }
+ }
+
+ LoggerContext genericHierarchy() {
+ if (genericHierarchy == null) {
+ File f = new File(dir, GENERIC + CONFIG_FILE_EXT);
+ if (f.exists()) {
+ genericHierarchy = new LoggerContext();
+ try {
+ JoranConfigurator configurator = new JoranConfigurator();
+ configurator.setContext(genericHierarchy);
+ configurator.doConfigure(f.getAbsolutePath());
+ } catch (JoranException je) {
+ StatusPrinter.print(genericHierarchy);
+ }
+ } else {
+ logger.warn("Could not find config file [" + f
+ + "]. Will use the default hierarchy.");
+ genericHierarchy = new LoggerContext();
+ }
+ }
+ return genericHierarchy;
+ }
}
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/BasicJoranTest.java Sun Oct 15 19:44:14 2006
@@ -17,6 +17,7 @@
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.classic.util.Constants;
import ch.qos.logback.core.appender.ListAppender;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
public class BasicJoranTest extends TestCase {
@@ -25,7 +26,7 @@
super(name);
}
- public void testSimpleList() {
+ public void testSimpleList() throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
@@ -44,7 +45,7 @@
assertEquals(msg, le.getMessage());
}
- public void testLevel() {
+ public void testLevel() throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
@@ -63,7 +64,7 @@
//assertEquals(msg, le.getMessage());
}
- public void testEval() {
+ public void testEval() throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
@@ -78,6 +79,7 @@
}
+ // COMMENTED_OUT_
public static Test COMMENTED_OUT_suite() {
TestSuite suite = new TestSuite();
suite.addTest(new BasicJoranTest("testLevel"));
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/joran/EvaluatorJoranTest.java Sun Oct 15 19:44:14 2006
@@ -24,12 +24,13 @@
import ch.qos.logback.classic.util.Constants;
import ch.qos.logback.core.CoreGlobal;
import ch.qos.logback.core.boolex.EvaluationException;
+import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
public class EvaluatorJoranTest extends TestCase {
- public void xtest() throws NullPointerException, EvaluationException {
+ public void xtest() throws NullPointerException, EvaluationException, JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
@@ -50,13 +51,13 @@
//StatusPrinter.print(loggerContext.getStatusManager());
}
- public void testIgnoreMarker() throws NullPointerException, EvaluationException {
+ public void testIgnoreMarker() throws NullPointerException, EvaluationException, JoranException {
JoranConfigurator jc = new JoranConfigurator();
LoggerContext loggerContext = new LoggerContext();
jc.setContext(loggerContext);
jc.doConfigure(Constants.TEST_DIR_PREFIX + "input/joran/ignore.xml");
-
+ StatusPrinter.print(loggerContext.getStatusManager());
Map evalMap = (Map) loggerContext.getObject(CoreGlobal.EVALUATOR_MAP);
assertNotNull(evalMap);
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/GenericConfigurator.java Sun Oct 15 19:44:14 2006
@@ -7,18 +7,23 @@
import java.net.URL;
import java.util.List;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
import org.xml.sax.InputSource;
+import ch.qos.logback.core.joran.spi.EventPlayer;
+import ch.qos.logback.core.joran.spi.ExecutionContext;
+import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.JoranException;
+import ch.qos.logback.core.joran.spi.RuleStore;
import ch.qos.logback.core.joran.spi.SaxEvent;
import ch.qos.logback.core.joran.spi.SaxEventRecorder;
+import ch.qos.logback.core.joran.spi.SimpleRuleStore;
import ch.qos.logback.core.spi.ContextAwareBase;
-public class GenericConfigurator extends ContextAwareBase {
+public abstract class GenericConfigurator extends ContextAwareBase {
+ List<SaxEvent> saxEventList;
+ Interpreter interpreter;
+
final public void doConfigure(URL url) throws JoranException {
try {
InputStream in = url.openStream();
@@ -61,42 +66,31 @@
doConfigure(new InputSource(inputStream));
}
- List<SaxEvent> recordEvents(InputSource inputSource) throws JoranException {
- SAXParser saxParser = null;
- SaxEventRecorder saxEventRecorder = new SaxEventRecorder();
- try {
- SAXParserFactory spf = SAXParserFactory.newInstance();
- spf.setValidating(false);
- spf.setNamespaceAware(true);
- saxParser = spf.newSAXParser();
- } catch (Exception pce) {
- String errMsg = "Parser configuration error occured";
- addError(errMsg, pce);
- throw new JoranException(errMsg, pce);
- }
-
- try {
- saxParser.parse(inputSource, saxEventRecorder);
- return saxEventRecorder.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);
- }
-
+ abstract protected void addInstanceRules(RuleStore rs);
+ abstract protected void addImpliciutRules(Interpreter interpreter);
+
+ protected void buildInterpreter() {
+ RuleStore rs = new SimpleRuleStore(context);
+ addInstanceRules(rs);
+ this.interpreter = new Interpreter(rs);
+ ExecutionContext ec = interpreter.getExecutionContext();
+ ec.setContext(context);
+ addImpliciutRules(interpreter);
+
}
-
+
final public void doConfigure(final InputSource inputSource)
throws JoranException {
-
- List<SaxEvent> saxEventList;
- saxEventList = recordEvents(inputSource);
-
+ SaxEventRecorder recorder = new SaxEventRecorder();
+ recorder.setContext(context);
+ saxEventList = recorder.recordEvents(inputSource);
+ buildInterpreter();
+ EventPlayer player = new EventPlayer(interpreter);
+ player.play(recorder.saxEventList);
+ }
+
+ public List<SaxEvent> getSaxEventList() {
+ return saxEventList;
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/JoranConfiguratorBase.java Sun Oct 15 19:44:14 2006
@@ -7,15 +7,10 @@
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation.
*/
-
-package ch.qos.logback.core.joran;
+package ch.qos.logback.core.joran;
-import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,7 +20,6 @@
import org.xml.sax.InputSource;
-import ch.qos.logback.core.Context;
import ch.qos.logback.core.joran.action.ActionConst;
import ch.qos.logback.core.joran.action.AppenderAction;
import ch.qos.logback.core.joran.action.AppenderRefAction;
@@ -40,89 +34,46 @@
import ch.qos.logback.core.joran.spi.Interpreter;
import ch.qos.logback.core.joran.spi.Pattern;
import ch.qos.logback.core.joran.spi.RuleStore;
-import ch.qos.logback.core.joran.spi.SimpleRuleStore;
-import ch.qos.logback.core.spi.ContextAwareBase;
-
-// Based on 310985 revision 310985 as attested by http://tinyurl.com/8njps
+// Based on 310985 revision 310985 as attested by http://tinyurl.com/8njps
// see also http://tinyurl.com/c2rp5
/**
- * A JoranConfiguratorBase lays most of the groundwork for concrete
- * configurators derived from it. Concrete configurators only need to
- * implement the {@link #addInstanceRules} method.
+ * A JoranConfiguratorBase lays most of the groundwork for concrete
+ * configurators derived from it. Concrete configurators only need to implement
+ * the {@link #addInstanceRules} method.
* <p>
* A JoranConfiguratorBase instance should not be used more than once to
* configure a Context.
- *
+ *
* @author Ceki Gülcü
*/
-abstract public class JoranConfiguratorBase extends ContextAwareBase {
- Interpreter joranInterpreter;
-
-
- final public void doConfigure(URL url) {
- try {
- InputStream in = url.openStream();
- doConfigure(in);
- in.close();
- } catch (IOException ioe) {
- String errMsg = "Could not open URL [" + url + "].";
- addError(errMsg, ioe);
- }
- }
+abstract public class JoranConfiguratorBase extends GenericConfigurator {
- final public void doConfigure(String filename) {
- doConfigure(new File(filename));
- }
- final public void doConfigure(File file) {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(file);
- doConfigure(fis);
- } catch (IOException ioe) {
- String errMsg = "Could not open [" + file.getName() + "].";
- addError(errMsg, ioe);
- } finally {
- if (fis != null) {
- try {
- fis.close();
- } catch (java.io.IOException ioe) {
- addError(
- "Could not close [" + file.getName() + "].", ioe);
- }
- }
- }
- }
-
- final public void doConfigure(InputStream inputStream) {
- doConfigure(new InputSource(inputStream));
- }
-
- final public void doConfigure(final InputSource inputSource) {
- // This line is needed here because there is logging from inside this method.
- selfInitialize(this.context);
-
- ExecutionContext ec = joranInterpreter.getExecutionContext();
+ final public void xdoConfigure(final InputSource inputSource) {
+ // This line is needed here because there is logging from inside this
+ // method.
+ buildInterpreter();
+ ExecutionContext ec = interpreter.getExecutionContext();
SAXParser saxParser = null;
try {
- SAXParserFactory spf = SAXParserFactory.newInstance();
- spf.setValidating(false);
- spf.setNamespaceAware(true);
- saxParser = spf.newSAXParser();
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ spf.setValidating(false);
+ spf.setNamespaceAware(true);
+ saxParser = spf.newSAXParser();
} catch (Exception pce) {
String errMsg = "Parser configuration error occured";
ec.addError(errMsg, pce);
return;
}
-
+
try {
// attachListAppender(context);
- saxParser.parse(inputSource, joranInterpreter);
- } catch(IOException ie) {
+ saxParser.parse(inputSource, interpreter);
+ } catch (IOException ie) {
final String errMsg = "I/O error occurred while parsing xml file";
ec.addError(errMsg, ie);
} catch (Exception ex) {
@@ -130,57 +81,51 @@
addError(errMsg, ex);
return;
} finally {
- //detachListAppender(repository);
- }
+ // detachListAppender(repository);
+ }
}
public List getErrorList() {
return null;
}
- abstract public void addInstanceRules(RuleStore rs);
-
- protected void selfInitialize(Context context) {
- RuleStore rs = new SimpleRuleStore(context);
- addInstanceRules(rs);
-
- rs.addRule(
- new Pattern("configuration/substitutionProperty"),
- new SubstitutionPropertyAction());
- rs.addRule(
- new Pattern("configuration/repositoryProperty"),
- new RepositoryPropertyAction());
- rs.addRule(
- new Pattern("configuration/conversionRule"),
+ @Override
+ protected void addInstanceRules(RuleStore rs) {
+ rs.addRule(new Pattern("configuration/substitutionProperty"),
+ new SubstitutionPropertyAction());
+ rs.addRule(new Pattern("configuration/repositoryProperty"),
+ new RepositoryPropertyAction());
+ rs.addRule(new Pattern("configuration/conversionRule"),
new ConversionRuleAction());
-
- rs.addRule(
- new Pattern("configuration/appender"), new AppenderAction());
- rs.addRule(new Pattern("configuration/appender/appender-ref"),
+
+ rs.addRule(new Pattern("configuration/appender"), new AppenderAction());
+ rs.addRule(new Pattern("configuration/appender/appender-ref"),
new AppenderRefAction());
- rs.addRule(
- new Pattern("configuration/newRule"), new NewRuleAction());
+ rs.addRule(new Pattern("configuration/newRule"), new NewRuleAction());
rs.addRule(new Pattern("*/param"), new ParamAction());
-
- joranInterpreter = new Interpreter(rs);
- ExecutionContext ec = joranInterpreter.getExecutionContext();
- ec.setContext(context);
-
+ }
+
+ @Override
+ protected void addImpliciutRules(Interpreter interpreter) {
// The following line adds the capability to parse nested components
NestedComponentIA nestedIA = new NestedComponentIA();
nestedIA.setContext(context);
- joranInterpreter.addImplicitAction(nestedIA);
+ interpreter.addImplicitAction(nestedIA);
NestedSimplePropertyIA nestedSimpleIA = new NestedSimplePropertyIA();
nestedIA.setContext(context);
- joranInterpreter.addImplicitAction(nestedSimpleIA);
+ interpreter.addImplicitAction(nestedSimpleIA);
+ }
- Map<String, Object> omap = ec.getObjectMap();
+ @Override
+ protected void buildInterpreter() {
+ super.buildInterpreter();
+ Map<String, Object> omap = interpreter.getExecutionContext().getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
omap.put(ActionConst.FILTER_CHAIN_BAG, new HashMap());
}
public ExecutionContext getExecutionContext() {
- return joranInterpreter.getExecutionContext();
+ return interpreter.getExecutionContext();
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/AbstractEventEvaluatorAction.java Sun Oct 15 19:44:14 2006
@@ -39,7 +39,7 @@
String className = attributes.getValue(CLASS_ATTRIBUTE);
if(OptionHelper.isEmpty(className)) {
className = defaultClassName();
- addError("Assuming default evaluator class ["+className+"]");
+ addWarn("Assuming default evaluator class ["+className+"]");
}
if(OptionHelper.isEmpty(className)) {
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/action/NestedComponentIA.java Sun Oct 15 19:44:14 2006
@@ -55,6 +55,7 @@
switch (containmentType) {
case PropertySetter.NOT_FOUND:
+ case PropertySetter.AS_PROPERTY:
return false;
// we only push action data if NestComponentIA is applicable
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/BodyEvent.java Sun Oct 15 19:44:14 2006
@@ -3,9 +3,9 @@
import org.xml.sax.Locator;
public class BodyEvent extends SaxEvent {
-
- final String text;
-
+
+ private String text;
+
BodyEvent(String text, Locator locator) {
super(null, null, null, locator);
this.text = text;
@@ -14,10 +14,15 @@
public String getText() {
return text;
}
-
+
@Override
public String toString() {
- return "BodyEvent("+getText()+")"+locator.getLineNumber()+","+locator.getColumnNumber();
+ return "BodyEvent(" + getText() + ")" + locator.getLineNumber() + ","
+ + locator.getColumnNumber();
+ }
+
+ public void append(String str) {
+ text += str;
}
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/EventPlayer.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,26 @@
+package ch.qos.logback.core.joran.spi;
+
+import java.util.List;
+
+public class EventPlayer {
+
+ final Interpreter interpreter;
+
+ public EventPlayer(Interpreter interpreter) {
+ this.interpreter = interpreter;
+ }
+
+ public void play(List<SaxEvent> seList) {
+ for(SaxEvent se : seList) {
+ if(se instanceof StartEvent) {
+ interpreter.startElement((StartEvent) se);
+ }
+ if(se instanceof BodyEvent) {
+ interpreter.characters((BodyEvent) se);
+ }
+ if(se instanceof EndEvent) {
+ interpreter.endElement((EndEvent) se);
+ }
+ }
+ }
+}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/Interpreter.java Sun Oct 15 19:44:14 2006
@@ -66,10 +66,7 @@
Pattern pattern;
Locator locator;
- public List<SaxEvent> saxEventList = new ArrayList<SaxEvent>();
-
-
- /**
+ /**
* The <id>actionListStack</id> contains a list of actions that are executing
* for the given XML element.
*
@@ -100,13 +97,17 @@
public void startDocument() {
}
+ public void startElement(StartEvent se) {
+ setDocumentLocator(se.getLocator());
+ startElement(se.namespaceURI, se.localName, se.qName, se.attributes);
+ }
+
public void startElement(String namespaceURI, String localName, String qName,
Attributes atts) {
-
- String tagName = getTagName(localName, qName);
+ String tagName = getTagName(localName, qName);
- //System.out.println("startElement [" + tagName + "]");
+ // System.out.println("startElement [" + tagName + "]");
pattern.push(tagName);
@@ -124,23 +125,28 @@
}
}
- public void characters(char[] ch, int start, int length) {
+ public void characters(BodyEvent be) {
+
+ setDocumentLocator(be.locator);
- String body = new String(ch, start, length);
+ String body = be.getText();
List applicableActionList = (List) actionListStack.peek();
- if(body != null) {
+ if (body != null) {
body = body.trim();
}
- if(body.length() > 0) {
- //System.out.println("calling body method with ["+body+ "]");
+ if (body.length() > 0) {
+ // System.out.println("calling body method with ["+body+ "]");
callBodyAction(applicableActionList, body);
}
}
+ public void endElement(EndEvent endEvent) {
+ setDocumentLocator(endEvent.locator);
+ endElement(endEvent.namespaceURI, endEvent.localName, endEvent.qName);
+ }
+
public void endElement(String namespaceURI, String localName, String qName) {
- saxEventList.add(new EndEvent(namespaceURI, localName, qName, getLocator()));
-
List applicableActionList = (List) actionListStack.pop();
// System.out.println("endElement ["+getTagName(localName, qName)+"]");
@@ -275,7 +281,8 @@
try {
action.body(ec, body);
} catch (ActionException ae) {
- ec.addError("Exception in end() methd for action [" + action+ "]", this, ae);
+ ec.addError("Exception in end() methd for action [" + action + "]",
+ this, ae);
}
}
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEvent.java Sun Oct 15 19:44:14 2006
@@ -33,9 +33,4 @@
public String getQName() {
return qName;
}
-
- @Override
- public String toString() {
- return this.getClass().getName()+", "+locator.getLineNumber()+","+locator.getColumnNumber();
- }
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/SaxEventRecorder.java Sun Oct 15 19:44:14 2006
@@ -1,22 +1,68 @@
package ch.qos.logback.core.joran.spi;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
-public class SaxEventRecorder extends DefaultHandler {
-
- private ExecutionContext ec;
-
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.spi.ContextAware;
+import ch.qos.logback.core.spi.ContextAwareImpl;
+import ch.qos.logback.core.status.Status;
+
+public class SaxEventRecorder extends DefaultHandler implements ContextAware {
+
+ ContextAwareImpl cai = new ContextAwareImpl();
+
public List<SaxEvent> saxEventList = new ArrayList<SaxEvent>();
Locator locator;
- Pattern globalPattern;
-
+ Pattern globalPattern = new Pattern();
+
+
+ final public void recordEvents(InputStream inputStream) throws JoranException {
+ recordEvents(new InputSource(inputStream));
+ }
+
+ public List<SaxEvent> recordEvents(InputSource inputSource)
+ throws JoranException {
+ SAXParser saxParser = null;
+ try {
+ SAXParserFactory spf = SAXParserFactory.newInstance();
+ spf.setValidating(false);
+ spf.setNamespaceAware(true);
+ saxParser = 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() {
}
@@ -28,33 +74,55 @@
locator = l;
}
-
public void startElement(String namespaceURI, String localName, String qName,
Attributes atts) {
String tagName = getTagName(localName, qName);
globalPattern.push(tagName);
Pattern current = (Pattern) globalPattern.clone();
- saxEventList.add(new StartEvent(current, namespaceURI, localName, qName, atts, getLocator()));
- }
+ saxEventList.add(new StartEvent(current, namespaceURI, localName, qName,
+ atts, getLocator()));
+ }
public void characters(char[] ch, int start, int length) {
- String body = new String(ch, start, length);
- if(body != null) {
- body = body.trim();
+ String body = new String(ch, start, length);
+ if (body == null) {
+ return;
+ }
+
+ // if the body string is null
+ if (body != null) {
+ String bodyTrimmed = body.trim();
+ if (bodyTrimmed.length() == 0) {
+ return;
+ }
}
- if(body.length() > 0) {
+
+ SaxEvent lastEvent = getLastEvent();
+ if (lastEvent instanceof BodyEvent) {
+ BodyEvent be = (BodyEvent) lastEvent;
+ be.append(body);
+ } else {
saxEventList.add(new BodyEvent(body, getLocator()));
}
+
+ }
+
+ SaxEvent getLastEvent() {
+ if (saxEventList.isEmpty()) {
+ return null;
+ }
+ int size = saxEventList.size();
+ return saxEventList.get(size - 1);
}
-
+
public void endElement(String namespaceURI, String localName, String qName) {
- saxEventList.add(new EndEvent(namespaceURI, localName, qName, getLocator()));
+ saxEventList
+ .add(new EndEvent(namespaceURI, localName, qName, getLocator()));
globalPattern.pop();
}
-
String getTagName(String localName, String qName) {
String tagName = localName;
if ((tagName == null) || (tagName.length() < 1)) {
@@ -62,22 +130,63 @@
}
return tagName;
}
-
+
public void error(SAXParseException spe) throws SAXException {
- ec.addError("Parsing error", this, spe);
- ec.addError("Parsing problem on line " + spe.getLineNumber()
- + " and column " + spe.getColumnNumber(), this, spe);
+ addError("Parsing error", spe);
+ addError("Parsing problem on line " + spe.getLineNumber() + " and column "
+ + spe.getColumnNumber(), spe);
}
public void fatalError(SAXParseException spe) throws SAXException {
- ec.addError("Parsing fatal error", this, spe);
- ec.addError("Parsing problem on line " + spe.getLineNumber()
- + " and column " + spe.getColumnNumber(), this, spe);
+ addError("Parsing fatal error", spe);
+ addError("Parsing problem on line " + spe.getLineNumber() + " and column "
+ + spe.getColumnNumber(), spe);
}
public void warning(SAXParseException spe) throws SAXException {
- ec.addWarn("Parsing warning", this, spe);
- ec.addWarn("Parsing problem on line " + spe.getLineNumber()
- + " and column " + spe.getColumnNumber(), this, spe);
+ addWarn("Parsing warning", spe);
+ addWarn("Parsing problem on line " + spe.getLineNumber() + " and column "
+ + spe.getColumnNumber(), spe);
}
+
+ public void addError(String msg) {
+ cai.addError(msg);
+ }
+
+ public void addError(String msg, Throwable ex) {
+ cai.addError(msg, ex);
+ }
+
+ public void addInfo(String msg) {
+ cai.addInfo(msg);
+ }
+
+ public void addInfo(String msg, Throwable ex) {
+ cai.addInfo(msg, ex);
+ }
+
+ public void addStatus(Status status) {
+ cai.addStatus(status);
+ }
+
+ public void addWarn(String msg) {
+ cai.addWarn(msg);
+ }
+
+ public void addWarn(String msg, Throwable ex) {
+ addWarn(msg, ex);
+ }
+
+ public Context getContext() {
+ return cai.getContext();
+ }
+
+ public void setContext(Context context) {
+ cai.setContext(context);
+ }
+
+ public List<SaxEvent> getSaxEventList() {
+ return saxEventList;
+ }
+
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/joran/spi/StartEvent.java Sun Oct 15 19:44:14 2006
@@ -2,6 +2,7 @@
import org.xml.sax.Attributes;
import org.xml.sax.Locator;
+import org.xml.sax.helpers.AttributesImpl;
public class StartEvent extends SaxEvent {
@@ -12,7 +13,7 @@
Attributes attributes, Locator locator) {
super(namespaceURI, localName, qName, locator);
// locator impl is used to take a snapshot!
- this.attributes = attributes;
+ this.attributes = new AttributesImpl(attributes);
this.pattern = pattern;
}
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareBase.java Sun Oct 15 19:44:14 2006
@@ -9,12 +9,6 @@
*/
package ch.qos.logback.core.spi;
-import ch.qos.logback.core.Context;
-import ch.qos.logback.core.status.ErrorStatus;
-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;
/**
@@ -23,65 +17,6 @@
*
* @author Ceki Gülcü
*/
-public class ContextAwareBase implements ContextAware {
-
- private int noContextWarning = 0;
- protected Context context;
-
- public void setContext(Context context) {
- if (this.context == null) {
- this.context = context;
- } else if (this.context != context) {
- throw new IllegalStateException("Context has been already set");
- }
- }
-
- public Context getContext() {
- return this.context;
- }
-
- public StatusManager getStatusManager() {
- if (context == null) {
- return null;
- }
- return context.getStatusManager();
- }
-
- public void addStatus(Status status) {
- if (context == null) {
- if (noContextWarning++ == 0) {
- System.out.println("LOGBACK: No context given for " + this);
- }
- return;
- }
- StatusManager sm = context.getStatusManager();
- if (sm != null) {
- sm.add(status);
- }
- }
-
- public void addInfo(String msg) {
- addStatus(new InfoStatus(msg, this));
- }
-
- public void addInfo(String msg, Throwable ex) {
- addStatus(new InfoStatus(msg, this, ex));
- }
-
- public void addWarn(String msg) {
- addStatus(new WarnStatus(msg, this));
- }
-
- public void addWarn(String msg, Throwable ex) {
- addStatus(new WarnStatus(msg, this, ex));
- }
-
- public void addError(String msg) {
- addStatus(new ErrorStatus(msg, this));
- }
-
- public void addError(String msg, Throwable ex) {
- addStatus(new ErrorStatus(msg, this, ex));
- }
-
+public class ContextAwareBase extends ContextAwareImpl {
+ // to be removed
}
Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/spi/ContextAwareImpl.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,87 @@
+/**
+ * LOGBack: the reliable, fast and flexible logging library for Java.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ */
+package ch.qos.logback.core.spi;
+
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.status.ErrorStatus;
+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;
+
+
+/**
+ * A helper class that implements ContextAware methods. This class can be either
+ * extended or alternatively included as a component.
+ *
+ * @author Ceki Gülcü
+ */
+public class ContextAwareImpl implements ContextAware {
+
+ private int noContextWarning = 0;
+ protected Context context;
+
+ public void setContext(Context context) {
+ if (this.context == null) {
+ this.context = context;
+ } else if (this.context != context) {
+ throw new IllegalStateException("Context has been already set");
+ }
+ }
+
+ public Context getContext() {
+ return this.context;
+ }
+
+ public StatusManager getStatusManager() {
+ if (context == null) {
+ return null;
+ }
+ return context.getStatusManager();
+ }
+
+ public void addStatus(Status status) {
+ if (context == null) {
+ if (noContextWarning++ == 0) {
+ System.out.println("LOGBACK: No context given for " + this);
+ }
+ return;
+ }
+ StatusManager sm = context.getStatusManager();
+ if (sm != null) {
+ sm.add(status);
+ }
+ }
+
+ public void addInfo(String msg) {
+ addStatus(new InfoStatus(msg, this));
+ }
+
+ public void addInfo(String msg, Throwable ex) {
+ addStatus(new InfoStatus(msg, this, ex));
+ }
+
+ public void addWarn(String msg) {
+ addStatus(new WarnStatus(msg, this));
+ }
+
+ public void addWarn(String msg, Throwable ex) {
+ addStatus(new WarnStatus(msg, this, ex));
+ }
+
+ public void addError(String msg) {
+ addStatus(new ErrorStatus(msg, this));
+ }
+
+ public void addError(String msg, Throwable ex) {
+ addStatus(new ErrorStatus(msg, this, ex));
+ }
+
+}
Added: logback/trunk/logback-core/src/test/input/joran/ampEvent.xml
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/input/joran/ampEvent.xml Sun Oct 15 19:44:14 2006
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<test>xxx & yyy</test>
Modified: logback/trunk/logback-core/src/test/input/joran/event1.xml
==============================================================================
--- logback/trunk/logback-core/src/test/input/joran/event1.xml (original)
+++ logback/trunk/logback-core/src/test/input/joran/event1.xml Sun Oct 15 19:44:14 2006
@@ -9,6 +9,6 @@
<touch/>
</badBegin>
- <hello name="John Doe">XXX</hello>
+ <hello name="John Doe">XXX&</hello>
</test>
\ No newline at end of file
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/AllTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/AllTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/AllTest.java Sun Oct 15 19:44:14 2006
@@ -15,7 +15,7 @@
suite.addTest(ch.qos.logback.core.appender.PackageTest.suite());
suite.addTest(ch.qos.logback.core.rolling.helper.PackageTest.suite());
suite.addTest(ch.qos.logback.core.rolling.PackageTest.suite());
- suite.addTest(ch.qos.logback.core.joran.spi.PackageTest.suite());
+ suite.addTest(ch.qos.logback.core.joran.PackageTest.suite());
return suite;
}
}
Copied: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java (from r678, /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventInterpreterTest.java)
==============================================================================
--- /logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventInterpreterTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/EventRecorderTest.java Sun Oct 15 19:44:14 2006
@@ -9,19 +9,23 @@
*/
package ch.qos.logback.core.joran;
+import java.io.FileInputStream;
+import java.util.List;
+
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
+import junit.framework.Test;
import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import ch.qos.logback.core.Context;
import ch.qos.logback.core.ContextBase;
-import ch.qos.logback.core.joran.spi.ExecutionContext;
-import ch.qos.logback.core.joran.spi.Interpreter;
-import ch.qos.logback.core.joran.spi.RuleStore;
+import ch.qos.logback.core.joran.spi.BodyEvent;
import ch.qos.logback.core.joran.spi.SaxEvent;
-import ch.qos.logback.core.joran.spi.SimpleRuleStore;
+import ch.qos.logback.core.joran.spi.SaxEventRecorder;
+import ch.qos.logback.core.status.Status;
+import ch.qos.logback.core.status.StatusManager;
import ch.qos.logback.core.util.Constants;
-import ch.qos.logback.core.util.StatusPrinter;
-
/**
* Test the way Interpreter skips elements in case of exceptions thrown by
@@ -29,9 +33,11 @@
*
* @author Ceki Gulcu
*/
-public class EventInterpreterTest extends TestCase {
+public class EventRecorderTest extends TestCase {
+
+ Context context = new ContextBase();
- public EventInterpreterTest(String name) {
+ public EventRecorderTest(String name) {
super(name);
}
@@ -50,7 +56,23 @@
SAXParserFactory spf = SAXParserFactory.newInstance();
return spf.newSAXParser();
}
-
+
+ public List<SaxEvent> doTest(String filename) throws Exception {
+ SaxEventRecorder recorder = new SaxEventRecorder();
+ recorder.setContext(context);
+ FileInputStream fis = new FileInputStream(Constants.TEST_DIR_PREFIX
+ + "input/joran/"+ filename);
+ recorder.recordEvents(fis);
+ return recorder.getSaxEventList();
+
+
+ }
+
+ public void dump(List<SaxEvent> seList) {
+ for (SaxEvent se : seList) {
+ System.out.println(se);
+ }
+ }
/**
* Tests that whenever an action throws an exception, processing of child
* elements is skipped.
@@ -58,28 +80,30 @@
* @throws Exception
*/
public void test1() throws Exception {
- RuleStore rs = new SimpleRuleStore(new ContextBase());
-
- Interpreter jp = new Interpreter(rs);
- ExecutionContext ec = jp.getExecutionContext();
- ec.setContext(new ContextBase());
+ List<SaxEvent> seList = doTest("event1.xml");
+ StatusManager sm = context.getStatusManager();
+ assertTrue(sm.getLevel() == Status.INFO);
+ //dump(seList);
+ assertEquals(11, seList.size());
- SAXParser saxParser = createParser();
- saxParser.parse("file:" + Constants.TEST_DIR_PREFIX + "input/joran/event1.xml", jp);
-
- StatusPrinter.print(ec.getStatusManager());
- for(SaxEvent se : jp.saxEventList) {
- System.out.println(se);
- }
+ }
- }
+ public void test2() throws Exception {
+ List<SaxEvent> seList = doTest("ampEvent.xml");
+ StatusManager sm = context.getStatusManager();
+ assertTrue(sm.getLevel() == Status.INFO);
+ dump(seList);
+ assertEquals(3, seList.size());
+
+ BodyEvent be = (BodyEvent) seList.get(1);
+ assertEquals("xxx & yyy", be.getText());
+ }
-
-// public static Test suite() {
-// TestSuite suite = new TestSuite();
-// //suite.addTest(new SkippingInInterpreterTest("testSkipSiblings2"));
-// suite.addTestSuite(SkippingInInterpreterTest.class);
-// return suite;
-// }
+ public static Test XXXsuite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new EventRecorderTest("test2"));
+ // suite.addTestSuite(SkippingInInterpreterTest.class);
+ return suite;
+ }
}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/PackageTest.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,17 @@
+package ch.qos.logback.core.joran;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class PackageTest extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTestSuite(SkippingInInterpreterTest.class);
+ suite.addTestSuite(EventRecorderTest.class);
+ suite.addTestSuite(TrivialcConfiguratorTest.class);
+ suite.addTest(ch.qos.logback.core.joran.spi.PackageTest.suite());
+ return suite;
+ }
+}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfigurator.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialConfigurator.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,20 @@
+package ch.qos.logback.core.joran;
+
+import ch.qos.logback.core.joran.action.IncAction;
+import ch.qos.logback.core.joran.spi.Interpreter;
+import ch.qos.logback.core.joran.spi.Pattern;
+import ch.qos.logback.core.joran.spi.RuleStore;
+
+public class TrivialConfigurator extends GenericConfigurator {
+
+ @Override
+ protected void addImpliciutRules(Interpreter interpreter) {
+ }
+
+ @Override
+ protected void addInstanceRules(RuleStore rs) {
+ rs.addRule(new Pattern("x/inc"), new IncAction());
+
+ }
+
+}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/TrivialcConfiguratorTest.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,42 @@
+package ch.qos.logback.core.joran;
+
+import junit.framework.TestCase;
+import ch.qos.logback.core.Context;
+import ch.qos.logback.core.ContextBase;
+import ch.qos.logback.core.joran.action.IncAction;
+import ch.qos.logback.core.util.Constants;
+
+public class TrivialcConfiguratorTest extends TestCase {
+
+ 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 {
+
+ TrivialConfigurator gc = new TrivialConfigurator();
+ gc.setContext(context);
+ gc.doConfigure(Constants.TEST_DIR_PREFIX
+ + "input/joran/"+ filename);
+ }
+
+ public void test() throws Exception {
+ int oldBeginCount = IncAction.beginCount;
+ int oldEndCount = IncAction.endCount;
+ doTest("inc.xml");
+ assertEquals(oldBeginCount+1, IncAction.beginCount);
+ assertEquals(oldEndCount+1, IncAction.endCount);
+
+ }
+
+}
Added: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/joran/action/IncAction.java Sun Oct 15 19:44:14 2006
@@ -0,0 +1,41 @@
+/**
+ * LOGBack: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 1999-2006, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+
+package ch.qos.logback.core.joran.action;
+
+import org.xml.sax.Attributes;
+
+import ch.qos.logback.core.joran.action.Action;
+import ch.qos.logback.core.joran.spi.ExecutionContext;
+
+
+
+public class IncAction extends Action {
+
+ static public int beginCount;
+ static public int endCount;
+
+ /**
+ * Instantiates an layout of the given class and sets its name.
+ *
+ */
+ public void begin(ExecutionContext ec, String name, Attributes attributes) {
+ System.out.println("IncAction Begin called");
+ beginCount++;
+ }
+
+ /**
+ * Once the children elements are also parsed, now is the time to activate
+ * the appender options.
+ */
+ public void end(ExecutionContext ec, String name) {
+ endCount++;
+ }
+}
1
0

svn commit: r682 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 17:29:11 2006
New Revision: 682
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
Log:
indentation changes only
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/TimeBasedRollingTest.java Sun Oct 15 17:29:11 2006
@@ -22,32 +22,31 @@
import ch.qos.logback.core.util.Compare;
import ch.qos.logback.core.util.Constants;
-
-
/**
* A rather exhaustive set of tests. Tests include leaving the ActiveFileName
- * argument blank, or setting it, with and without compression, and tests
- * with or without stopping/restarting the RollingFileAppender.
+ * argument blank, or setting it, with and without compression, and tests with
+ * or without stopping/restarting the RollingFileAppender.
*
- * The regression tests log a few times using a RollingFileAppender. Then,
- * they predict the names of the files which should be generated and compare
- * them with witness files.
+ * The regression tests log a few times using a RollingFileAppender. Then, they
+ * predict the names of the files which should be generated and compare them
+ * with witness files.
*
* <pre>
- Compression ActiveFileName Stop/Restart
- Test1 NO BLANK NO
- Test2 NO BLANK YES
- Test3 YES BLANK NO
- Test4 NO SET YES
- Test5 NO SET NO
- Test6 YES SET NO
+ * Compression ActiveFileName Stop/Restart
+ * Test1 NO BLANK NO
+ * Test2 NO BLANK YES
+ * Test3 YES BLANK NO
+ * Test4 NO SET YES
+ * Test5 NO SET NO
+ * Test6 YES SET NO
* </pre>
+ *
* @author Ceki Gülcü
*/
public class TimeBasedRollingTest extends TestCase {
static final String DATE_PATTERN = "yyyy-MM-dd_HH_mm_ss";
-
+
EchoLayout layout = new EchoLayout();
public TimeBasedRollingTest(String name) {
@@ -55,22 +54,22 @@
}
public void setUp() {
- //Delete .log files
- {
- File target = new File(Constants.TEST_DIR_PREFIX + "output/test4.log");
- target.mkdirs();
- target.delete();
- }
- {
- File target = new File(Constants.TEST_DIR_PREFIX + "output/test5.log");
- target.mkdirs();
- target.delete();
- }
- {
- File target = new File(Constants.TEST_DIR_PREFIX + "output/test6.log");
- target.mkdirs();
- target.delete();
- }
+ // Delete .log files
+ {
+ File target = new File(Constants.TEST_DIR_PREFIX + "output/test4.log");
+ target.mkdirs();
+ target.delete();
+ }
+ {
+ File target = new File(Constants.TEST_DIR_PREFIX + "output/test5.log");
+ target.mkdirs();
+ target.delete();
+ }
+ {
+ File target = new File(Constants.TEST_DIR_PREFIX + "output/test6.log");
+ target.mkdirs();
+ target.delete();
+ }
}
public void tearDown() {
@@ -85,19 +84,20 @@
rfa.setLayout(layout);
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{" + DATE_PATTERN + "}");
+ tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test1-%d{"
+ + DATE_PATTERN + "}");
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 4; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test1-" + sdf.format(cal.getTime());
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test1-"
+ + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
@@ -111,11 +111,12 @@
}
for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
+ // System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 4; i++) {
- assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test1." + i));
+ assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test1." + i));
}
}
@@ -127,11 +128,11 @@
rfa1.setLayout(layout);
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
- tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{" + DATE_PATTERN + "}");
+ tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+ + DATE_PATTERN + "}");
tbrp1.start();
rfa1.setRollingPolicy(tbrp1);
rfa1.start();
-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
String[] filenames = new String[4];
@@ -139,7 +140,8 @@
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 4; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test2-" + sdf.format(cal.getTime());
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test2-"
+ + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
@@ -152,26 +154,26 @@
Thread.sleep(500);
}
-
rfa1.stop();
RollingFileAppender rfa2 = new RollingFileAppender();
rfa2.setLayout(layout);
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
- tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{" + DATE_PATTERN + "}");
+ tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test2-%d{"
+ + DATE_PATTERN + "}");
tbrp2.start();
rfa2.setRollingPolicy(tbrp2);
rfa2.start();
-
for (int i = 3; i <= 4; i++) {
rfa2.doAppend("Hello---" + i);
Thread.sleep(500);
}
for (int i = 0; i < 4; i++) {
- assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test2." + i));
+ assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test2." + i));
}
}
@@ -182,21 +184,21 @@
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
-
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{" + DATE_PATTERN + "}.gz");
+ tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test3-%d{"
+ + DATE_PATTERN + "}.gz");
tbrp.start();
rfa.setRollingPolicy(tbrp);
rfa.start();
-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test3-" + sdf.format(cal.getTime()) + ".gz";
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test3-"
+ + sdf.format(cal.getTime()) + ".gz";
cal.add(Calendar.SECOND, 1);
}
@@ -212,42 +214,45 @@
}
for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
+ // System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 3; i++) {
- assertTrue(Compare.gzCompare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test3." + i + ".gz"));
+ assertTrue(Compare.gzCompare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test3." + i + ".gz"));
}
- assertTrue(Compare.compare(filenames[3], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test3.3"));
+ assertTrue(Compare.compare(filenames[3], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test3.3"));
}
/**
- * Without compression, activeFileName set, with stop/restart
+ * Without compression, activeFileName set, with stop/restart
*/
public void test4() throws Exception {
RollingFileAppender rfa1 = new RollingFileAppender();
rfa1.setLayout(layout);
-
+
TimeBasedRollingPolicy tbrp1 = new TimeBasedRollingPolicy();
tbrp1.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
- tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{" + DATE_PATTERN + "}");
+ tbrp1.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+ + DATE_PATTERN + "}");
tbrp1.start();
rfa1.setRollingPolicy(tbrp1);
rfa1.start();
-
SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN);
String[] filenames = new String[4];
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test4-" + sdf.format(cal.getTime());
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test4-"
+ + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
filenames[3] = Constants.TEST_DIR_PREFIX + "output/test4.log";
-
+
System.out.println("Waiting until next second and 100 millis.");
delayUntilNextSecond(100);
System.out.println("Done waiting.");
@@ -263,7 +268,8 @@
rfa2.setLayout(layout);
TimeBasedRollingPolicy tbrp2 = new TimeBasedRollingPolicy();
- tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{" + DATE_PATTERN + "}");
+ tbrp2.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test4-%d{"
+ + DATE_PATTERN + "}");
tbrp2.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test4.log");
tbrp2.start();
rfa2.setRollingPolicy(tbrp2);
@@ -275,19 +281,21 @@
}
for (int i = 0; i < 4; i++) {
- assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test4." + i));
+ assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test4." + i));
}
}
/**
- * No compression, activeFileName set, without stop/restart
+ * No compression, activeFileName set, without stop/restart
*/
public void test5() throws Exception {
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test5-%d{" + DATE_PATTERN + "}");
+ tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test5-%d{"
+ + DATE_PATTERN + "}");
tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test5.log");
tbrp.start();
rfa.setRollingPolicy(tbrp);
@@ -299,7 +307,8 @@
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test5-" + sdf.format(cal.getTime());
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test5-"
+ + sdf.format(cal.getTime());
cal.add(Calendar.SECOND, 1);
}
@@ -315,7 +324,8 @@
}
for (int i = 0; i < 4; i++) {
- assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test5." + i));
+ assertTrue(Compare.compare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test5." + i));
}
}
@@ -327,7 +337,8 @@
rfa.setLayout(layout);
TimeBasedRollingPolicy tbrp = new TimeBasedRollingPolicy();
- tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test6-%d{" + DATE_PATTERN + "}.gz");
+ tbrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/test6-%d{"
+ + DATE_PATTERN + "}.gz");
tbrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/test6.log");
tbrp.start();
rfa.setRollingPolicy(tbrp);
@@ -339,7 +350,8 @@
Calendar cal = Calendar.getInstance();
for (int i = 0; i < 3; i++) {
- filenames[i] = Constants.TEST_DIR_PREFIX + "output/test6-" + sdf.format(cal.getTime()) + ".gz";
+ filenames[i] = Constants.TEST_DIR_PREFIX + "output/test6-"
+ + sdf.format(cal.getTime()) + ".gz";
cal.add(Calendar.SECOND, 1);
}
@@ -355,78 +367,84 @@
}
for (int i = 0; i < 4; i++) {
- //System.out.println(i + " expected filename [" + filenames[i] + "].");
+ // System.out.println(i + " expected filename [" + filenames[i] + "].");
}
for (int i = 0; i < 3; i++) {
- assertTrue(Compare.gzCompare(filenames[i], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test6." + i + ".gz"));
+ assertTrue(Compare.gzCompare(filenames[i], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test6." + i + ".gz"));
}
- assertTrue(Compare.compare(filenames[3], Constants.TEST_DIR_PREFIX + "witness/rolling/tbr-test6.3"));
+ assertTrue(Compare.compare(filenames[3], Constants.TEST_DIR_PREFIX
+ + "witness/rolling/tbr-test6.3"));
}
-// public void testWithJoran1() throws Exception {
-// JoranConfigurator jc = new JoranConfigurator();
-// jc.doConfigure("./input/rolling/time1.xml", LogManager.getLoggerRepository());
-// jc.dumpErrors();
-//
-// String datePattern = "yyyy-MM-dd_HH_mm_ss";
-//
-// SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
-// String[] filenames = new String[4];
-//
-// Calendar cal = Calendar.getInstance();
-//
-// for (int i = 0; i < 4; i++) {
-// filenames[i] = "output/test1-" + sdf.format(cal.getTime());
-// cal.add(Calendar.SECOND, 1);
-// }
-//
-// System.out.println("Waiting until next second and 100 millis.");
-// delayUntilNextSecond(100);
-// System.out.println("Done waiting.");
-//
-// for (int i = 0; i < 5; i++) {
-// logger.debug("Hello---" + i);
-// Thread.sleep(500);
-// }
-//
-// for (int i = 0; i < 4; i++) {
-// //System.out.println(i + " expected filename [" + filenames[i] + "].");
-// }
-//
-// for (int i = 0; i < 4; i++) {
-// assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test1." + i));
-// }
-//
-// }
-//
-// public void XXXtestWithJoran10() throws Exception {
-// JoranConfigurator jc = new JoranConfigurator();
-// jc.doConfigure("./input/rolling/time2.xml", LogManager.getLoggerRepository());
-// jc.dumpErrors();
-//
-// String datePattern = "yyyy-MM-dd";
-//
-// SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
-// String[] filenames = new String[0];
-//
-// Calendar cal = Calendar.getInstance();
-//
-// filenames[0] = "output/test1-" + sdf.format(cal.getTime());
-//
-// for (int i = 0; i < 5; i++) {
-// logger.debug("Hello---" + i);
-// Thread.sleep(500);
-// }
-//
-//
-// for (int i = 0; i < 1; i++) {
-// assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test10." + i));
-// }
-//
-// }
-
+ // public void testWithJoran1() throws Exception {
+ // JoranConfigurator jc = new JoranConfigurator();
+ // jc.doConfigure("./input/rolling/time1.xml",
+ // LogManager.getLoggerRepository());
+ // jc.dumpErrors();
+ //
+ // String datePattern = "yyyy-MM-dd_HH_mm_ss";
+ //
+ // SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
+ // String[] filenames = new String[4];
+ //
+ // Calendar cal = Calendar.getInstance();
+ //
+ // for (int i = 0; i < 4; i++) {
+ // filenames[i] = "output/test1-" + sdf.format(cal.getTime());
+ // cal.add(Calendar.SECOND, 1);
+ // }
+ //
+ // System.out.println("Waiting until next second and 100 millis.");
+ // delayUntilNextSecond(100);
+ // System.out.println("Done waiting.");
+ //
+ // for (int i = 0; i < 5; i++) {
+ // logger.debug("Hello---" + i);
+ // Thread.sleep(500);
+ // }
+ //
+ // for (int i = 0; i < 4; i++) {
+ // //System.out.println(i + " expected filename [" + filenames[i] + "].");
+ // }
+ //
+ // for (int i = 0; i < 4; i++) {
+ // assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test1." +
+ // i));
+ // }
+ //
+ // }
+ //
+ // public void XXXtestWithJoran10() throws Exception {
+ // JoranConfigurator jc = new JoranConfigurator();
+ // jc.doConfigure("./input/rolling/time2.xml",
+ // LogManager.getLoggerRepository());
+ // jc.dumpErrors();
+ //
+ // String datePattern = "yyyy-MM-dd";
+ //
+ // SimpleDateFormat sdf = new SimpleDateFormat(datePattern);
+ // String[] filenames = new String[0];
+ //
+ // Calendar cal = Calendar.getInstance();
+ //
+ // filenames[0] = "output/test1-" + sdf.format(cal.getTime());
+ //
+ // for (int i = 0; i < 5; i++) {
+ // logger.debug("Hello---" + i);
+ // Thread.sleep(500);
+ // }
+ //
+ //
+ // for (int i = 0; i < 1; i++) {
+ // assertTrue(Compare.compare(filenames[i], "witness/rolling/tbr-test10." +
+ // i));
+ // }
+ //
+ // }
+
void delayUntilNextSecond(int millis) {
long now = System.currentTimeMillis();
Calendar cal = Calendar.getInstance();
@@ -458,15 +476,14 @@
} catch (Exception e) {
}
}
-
+
public static Test suite() {
TestSuite suite = new TestSuite();
// CompressTest requires external copying
// suite.addTestSuite(CompressTest.class);
- //suite.addTest(new TimeBasedRollingTest("test1"));
+ // suite.addTest(new TimeBasedRollingTest("test1"));
suite.addTestSuite(TimeBasedRollingTest.class);
return suite;
}
-
}
1
0

svn commit: r681 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 17:27:22 2006
New Revision: 681
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
Log:
indentation changes only
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/PackageTest.java Sun Oct 15 17:27:22 2006
@@ -6,7 +6,7 @@
public class PackageTest extends TestCase {
- public static Test suite() {
+ public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(RenamingTest.class);
suite.addTestSuite(SizeBasedRollingTest.class);
1
0

svn commit: r680 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 17:26:38 2006
New Revision: 680
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicyTest.java
Log:
indentation changes only
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicyTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicyTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedTriggeringPolicyTest.java Sun Oct 15 17:26:38 2006
@@ -6,39 +6,40 @@
public class SizeBasedTriggeringPolicyTest extends TestCase {
- public void testStringToLong() {
- Context context = new ContextBase();
- SizeBasedTriggeringPolicy policy = new SizeBasedTriggeringPolicy();
- policy.setContext(context);
-
- Long result;
-
- {
- result = policy.toFileSize("123");
- assertEquals(new Long("123"), result);
- }
- {
- result = policy.toFileSize("123KB");
- // = 123 * 1024
- assertEquals(new Long("125952"), result);
- }
- {
- result = policy.toFileSize("123MB");
- // = 123 * 1024 * 1024
- assertEquals(new Long("128974848"), result);
- }
- {
- result = policy.toFileSize("123GB");
- // = 123 * 1024 * 1024 * 1024
- assertEquals(new Long("132070244352"), result);
- }
-
- {
- result = policy.toFileSize("123xxxx");
- // = 123 * 1024 * 1024 * 1024
- assertEquals(new Long(SizeBasedTriggeringPolicy.DEFAULT_MAX_FILE_SIZE), result);
- assertEquals(2, context.getStatusManager().getCount());
- }
+ public void testStringToLong() {
+ Context context = new ContextBase();
+ SizeBasedTriggeringPolicy policy = new SizeBasedTriggeringPolicy();
+ policy.setContext(context);
+
+ Long result;
+
+ {
+ result = policy.toFileSize("123");
+ assertEquals(new Long("123"), result);
+ }
+ {
+ result = policy.toFileSize("123KB");
+ // = 123 * 1024
+ assertEquals(new Long("125952"), result);
+ }
+ {
+ result = policy.toFileSize("123MB");
+ // = 123 * 1024 * 1024
+ assertEquals(new Long("128974848"), result);
+ }
+ {
+ result = policy.toFileSize("123GB");
+ // = 123 * 1024 * 1024 * 1024
+ assertEquals(new Long("132070244352"), result);
+ }
+
+ {
+ result = policy.toFileSize("123xxxx");
+ // = 123 * 1024 * 1024 * 1024
+ assertEquals(new Long(SizeBasedTriggeringPolicy.DEFAULT_MAX_FILE_SIZE),
+ result);
+ assertEquals(2, context.getStatusManager().getCount());
+ }
- }
+ }
}
1
0

svn commit: r679 - logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling
by noreply.ceki@qos.ch 15 Oct '06
by noreply.ceki@qos.ch 15 Oct '06
15 Oct '06
Author: ceki
Date: Sun Oct 15 17:25:49 2006
New Revision: 679
Modified:
logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
Log:
indentation changes only
Modified: logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java
==============================================================================
--- logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java (original)
+++ logback/trunk/logback-core/src/test/java/ch/qos/logback/core/rolling/SizeBasedRollingTest.java Sun Oct 15 17:25:49 2006
@@ -28,7 +28,6 @@
import ch.qos.logback.core.util.Compare;
import ch.qos.logback.core.util.Constants;
-
/**
*
* Do not forget to call start() when configuring programatically.
@@ -42,18 +41,19 @@
public SizeBasedRollingTest(String name) {
super(name);
}
-
+
public void setUp() {
- {
- File target = new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.log");
- target.mkdirs();
- target.delete();
- }
- {
- File target = new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
- target.mkdirs();
- target.delete();
- }
+ {
+ File target = new File(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.log");
+ target.mkdirs();
+ target.delete();
+ }
+ {
+ File target = new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
+ target.mkdirs();
+ target.delete();
+ }
}
public void tearDown() {
@@ -66,7 +66,7 @@
public void test1() throws Exception {
// We purposefully use the \n as the line separator.
// This makes the regression test system independent.
- Context context = new ContextBase();
+ Context context = new ContextBase();
Layout layout = new DummyLayout();
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
@@ -76,32 +76,33 @@
fwrp.setContext(context);
SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
sbtp.setContext(context);
-
+
sbtp.setMaxFileSize("100");
sbtp.start();
- fwrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/sizeBased-test1.%i");
+ fwrp.setFileNamePattern(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test1.%i");
try {
fwrp.start();
fail("The absence of activeFileName option should have caused an exception.");
} catch (IllegalStateException e) {
return;
}
-
- //StatusPrinter.print(context.getStatusManager());
+
+ // StatusPrinter.print(context.getStatusManager());
}
/**
* Test basic rolling functionality.
*/
public void test2() throws Exception {
- Context context = new ContextBase();
-
+ Context context = new ContextBase();
+
DummyLayout layout = new DummyLayout();
RollingFileAppender rfa = new RollingFileAppender();
rfa.setName("ROLLING");
rfa.setLayout(layout);
rfa.setContext(context);
-
+
FixedWindowRollingPolicy swrp = new FixedWindowRollingPolicy();
swrp.setContext(context);
SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
@@ -109,107 +110,122 @@
sbtp.setMaxFileSize("100");
swrp.setMinIndex(0);
- swrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.log");
+ swrp.setActiveFileName(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.log");
- swrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.%i");
+ swrp.setFileNamePattern(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.%i");
swrp.start();
rfa.setRollingPolicy(swrp);
rfa.setTriggeringPolicy(sbtp);
rfa.start();
-
+
// Write exactly 10 bytes with each log
-// for (int i = 0; i < 25; i++) {
-// Thread.sleep(100);
-// if (i < 10) {
-// rfa.doAppend("Hello---" + i);
-// //logger.debug("Hello---" + i);
-// } else if (i < 100) {
-// rfa.doAppend("Hello---" + i);
-// //logger.debug("Hello--" + i);
-// }
-// }
-
+ // for (int i = 0; i < 25; i++) {
+ // Thread.sleep(100);
+ // if (i < 10) {
+ // rfa.doAppend("Hello---" + i);
+ // //logger.debug("Hello---" + i);
+ // } else if (i < 100) {
+ // rfa.doAppend("Hello---" + i);
+ // //logger.debug("Hello--" + i);
+ // }
+ // }
+
for (int i = 0; i < 45; i++) {
- Thread.sleep(100);
- rfa.doAppend("hello");
+ Thread.sleep(100);
+ rfa.doAppend("hello");
}
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.log").exists());
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.0").exists());
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.1").exists());
+ assertTrue(new File(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.log").exists());
+ assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.0")
+ .exists());
+ assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.1")
+ .exists());
// The File.length() method is not accurate under Windows
if (!isWindows()) {
- assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.log",
- Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test2.l"));
- assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.0",
- Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test2.0"));
- assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX + "output/sizeBased-test2.1",
- Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test2.1"));
+ assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.log", Constants.TEST_DIR_PREFIX
+ + "witness/rolling/sbr-test2.l"));
+ assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.0", Constants.TEST_DIR_PREFIX
+ + "witness/rolling/sbr-test2.0"));
+ assertTrue(Compare.compare(Constants.TEST_DIR_PREFIX
+ + "output/sizeBased-test2.1", Constants.TEST_DIR_PREFIX
+ + "witness/rolling/sbr-test2.1"));
}
-
- //StatusPrinter.print(context.getStatusManager());
+
+ // StatusPrinter.print(context.getStatusManager());
}
/**
* Same as testBasic but also with GZ compression.
*/
public void test3() throws Exception {
- Context context = new ContextBase();
+ Context context = new ContextBase();
DummyLayout layout = new DummyLayout();
RollingFileAppender rfa = new RollingFileAppender();
rfa.setLayout(layout);
rfa.setContext(context);
-
+
FixedWindowRollingPolicy fwrp = new FixedWindowRollingPolicy();
fwrp.setContext(context);
SizeBasedTriggeringPolicy sbtp = new SizeBasedTriggeringPolicy();
sbtp.setContext(context);
-
+
sbtp.setMaxFileSize("100");
fwrp.setMinIndex(0);
fwrp.setActiveFileName(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log");
- fwrp.setFileNamePattern(Constants.TEST_DIR_PREFIX + "output/sbr-test3.%i.gz");
+ fwrp.setFileNamePattern(Constants.TEST_DIR_PREFIX
+ + "output/sbr-test3.%i.gz");
fwrp.start();
rfa.setRollingPolicy(fwrp);
rfa.setTriggeringPolicy(sbtp);
rfa.start();
// Write exactly 10 bytes with each log
-// for (int i = 0; i < 25; i++) {
-// Thread.sleep(100);
-// if (i < 10) {
-// rfa.doAppend("Hello---" + i);
-// //logger.debug("Hello---" + i);
-// } else if (i < 100) {
-// rfa.doAppend("Hello---" + i);
-// //logger.debug("Hello--" + i);
-// }
-// }
+ // for (int i = 0; i < 25; i++) {
+ // Thread.sleep(100);
+ // if (i < 10) {
+ // rfa.doAppend("Hello---" + i);
+ // //logger.debug("Hello---" + i);
+ // } else if (i < 100) {
+ // rfa.doAppend("Hello---" + i);
+ // //logger.debug("Hello--" + i);
+ // }
+ // }
for (int i = 0; i < 45; i++) {
- Thread.sleep(100);
- rfa.doAppend("hello");
+ Thread.sleep(100);
+ rfa.doAppend("hello");
}
-
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log").exists());
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.0.gz").exists());
- assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.1.gz").exists());
+
+ assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.log")
+ .exists());
+ assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.0.gz")
+ .exists());
+ assertTrue(new File(Constants.TEST_DIR_PREFIX + "output/sbr-test3.1.gz")
+ .exists());
if (!isWindows()) {
- assertTrue(Compare.compare("Constants.TEST_DIR_PREFIXoutput/sbr-test3.log",
- Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.l"));
- assertTrue(Compare.gzCompare("Constants.TEST_DIR_PREFIXoutput/sbr-test3.0.gz",
+ assertTrue(Compare.compare(
+ "Constants.TEST_DIR_PREFIXoutput/sbr-test3.log",
+ Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.l"));
+ assertTrue(Compare.gzCompare(
+ "Constants.TEST_DIR_PREFIXoutput/sbr-test3.0.gz",
Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.0.gz"));
- assertTrue(Compare.gzCompare("Constants.TEST_DIR_PREFIXoutput/sbr-test3.1.gz",
- Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.1.gz"));
+ assertTrue(Compare.gzCompare(
+ "Constants.TEST_DIR_PREFIXoutput/sbr-test3.1.gz",
+ Constants.TEST_DIR_PREFIX + "witness/rolling/sbr-test3.1.gz"));
}
- //StatusPrinter.print(context.getStatusManager());
+ // StatusPrinter.print(context.getStatusManager());
}
boolean isWindows() {
1
0