ceki 2003/09/12 11:24:26
Modified: docs .cvsignore
tests/witness simple ttcc
src/java/org/apache/joran/action AppenderAction.java
AppenderRefAction.java RootLoggerAction.java
LoggerAction.java
src/java/org/apache/joran JoranParser.java RuleStore.java
src/java/org/apache/log4j/pattern PatternParser.java
src/java/org/apache/log4j PatternLayout.java
tests/src/java/org/apache/joran JoranParserTest.java
tests/src/java/org/apache/log4j MinimumTestCase.java
tests/src/java/org/apache/log4j/helpers
BoundedFIFOTestCase.java
Added: tests/input/joran parser3.xml
tests/src/java/org/apache/log4j/util
JunitTestRunnerFilter.java
src/java/org/apache/joran/action NestComponentIA.java
ImplicitAction.java
src/java/org/apache/joran/helper Option.java
Removed: src/java/org/apache/joran ImplicitRule.java
Log:
- Fixed a few JUnit tests to allow them to run under Eclipse.
- Joran now handles implicit rules. It can congifure the triggering
policy and rolling policy in RollingAppender.
- PatternLayout can now learn new conversion rules. (NOT YET TESTED)
Revision Changes Path
1.5 +2 -1 jakarta-log4j/docs/.cvsignore
Index: .cvsignore
===================================================================
RCS file: /home/cvs/jakarta-log4j/docs/.cvsignore,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- .cvsignore 11 Sep 2003 17:25:24 -0000 1.4
+++ .cvsignore 12 Sep 2003 18:24:26 -0000 1.5
@@ -7,4 +7,5 @@
download.html
earlier.html
history.html
-index.html
\ No newline at end of file
+index.html
+package-list
1.1 jakarta-log4j/tests/input/joran/parser3.xml
Index: parser3.xml
===================================================================
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
1
<appender name="A1" class="org.apache.log4j.rolling.RollingFileAppender">
<param name="File" value="output/temp.A1" />
<param name="Append" value="false" />
2
<rollingPolicy class="org.apache.log4j.rolling.SlidingWindowRollingPolicy">
<param name="activeFileName" value="output/parser3"/>
<param name="fileNamePattern" value="output/parser3.%i"/>
</rollingPolicy>
3
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="maxFileSize" value="100"/>
</triggeringPolicy>
4
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p %c{2} - %m%n"/>
</layout>
</appender>
5
6
<logger>
<level value ="debug" />
<appender-ref ref="A1" />
</logger>
7
<logger name="asd">
<level value ="debug" />
<appender-ref ref="A1" />
</logger>
8
<root>
<level value ="debug" />
<appender-ref ref="A1" />
</root>
9
</log4j:configuration>
1.4 +0 -2 jakarta-log4j/tests/witness/simple
Index: simple
===================================================================
RCS file: /home/cvs/jakarta-log4j/tests/witness/simple,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- simple 14 Nov 2002 08:48:40 -0000 1.3
+++ simple 12 Sep 2003 18:24:26 -0000 1.4
@@ -34,6 +34,4 @@
at junit.framework.TestCase.run(X)
at junit.framework.TestSuite.runTest(X)
at junit.framework.TestSuite.run(X)
- at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(X)
- at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(X)
INFO - Messages should bear numbers 0 through 23.
1.4 +0 -2 jakarta-log4j/tests/witness/ttcc
Index: ttcc
===================================================================
RCS file: /home/cvs/jakarta-log4j/tests/witness/ttcc,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ttcc 14 Nov 2002 08:48:40 -0000 1.3
+++ ttcc 12 Sep 2003 18:24:26 -0000 1.4
@@ -34,6 +34,4 @@
at junit.framework.TestCase.run(X)
at junit.framework.TestSuite.runTest(X)
at junit.framework.TestSuite.run(X)
- at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(X)
- at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(X)
[main] INFO INF - Messages should bear numbers 0 through 23.
1.1
jakarta-log4j/tests/src/java/org/apache/log4j/util/JunitTestRunnerFilter.java
Index: JunitTestRunnerFilter.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.log4j.util;
import org.apache.oro.text.perl.Perl5Util;
public class JunitTestRunnerFilter implements Filter {
Perl5Util util = new Perl5Util();
/**
* Filter out stack trace lines coming from the various JUnit TestRunners.
*/
public String filter(String in) {
if(in == null)
return null;
if (util.match("/at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner/",
in)) {
return null;
} else if (util.match("/at
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner/", in)) {
return in;
} else {
return in;
}
}
}
1.3 +2 -1
jakarta-log4j/src/java/org/apache/joran/action/AppenderAction.java
Index: AppenderAction.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/joran/action/AppenderAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AppenderAction.java 11 Sep 2003 17:00:42 -0000 1.2
+++ AppenderAction.java 12 Sep 2003 18:24:26 -0000 1.3
@@ -50,6 +50,7 @@
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
+import org.apache.joran.helper.Option;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
@@ -86,7 +87,7 @@
String appenderName =
appenderElement.getAttribute(ActionConst.NAME_ATTRIBUTE);
- if (appenderName == null) {
+ if (Option.isEmpty(appenderName)) {
logger.warn(
"No appender name given for appender of type " + className + "].");
} else {
1.4 +2 -1
jakarta-log4j/src/java/org/apache/joran/action/AppenderRefAction.java
Index: AppenderRefAction.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/joran/action/AppenderRefAction.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AppenderRefAction.java 11 Sep 2003 17:25:24 -0000 1.3
+++ AppenderRefAction.java 12 Sep 2003 18:24:26 -0000 1.4
@@ -50,6 +50,7 @@
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
+import org.apache.joran.helper.Option;
import org.apache.log4j.Appender;
import org.apache.log4j.Logger;
import org.apache.log4j.spi.AppenderAttachable;
@@ -84,7 +85,7 @@
String appenderName = appenderRef.getAttribute(ActionConst.REF_ATTRIBUTE);
- if (appenderName == null) {
+ if (Option.isEmpty(appenderName)) {
// print a meaningful error message and return
Node parentNode = appenderRef.getParentNode();
String errMsg = "Missing appender ref attribute in <appender-ref> tag.";
1.3 +1 -1
jakarta-log4j/src/java/org/apache/joran/action/RootLoggerAction.java
Index: RootLoggerAction.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/joran/action/RootLoggerAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- RootLoggerAction.java 11 Sep 2003 17:25:24 -0000 1.2
+++ RootLoggerAction.java 12 Sep 2003 18:24:26 -0000 1.3
@@ -91,7 +91,7 @@
"The object on the top the of the stack is not the root logger");
logger.warn("It is: "+o);
} else {
- logger.debug("Removing root logger from stack.");
+ logger.debug("Removing root logger from top of stack.");
ec.popObject();
}
}
1.3 +2 -1 jakarta-log4j/src/java/org/apache/joran/action/LoggerAction.java
Index: LoggerAction.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/joran/action/LoggerAction.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LoggerAction.java 11 Sep 2003 17:25:24 -0000 1.2
+++ LoggerAction.java 12 Sep 2003 18:24:26 -0000 1.3
@@ -1,6 +1,7 @@
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
+import org.apache.joran.helper.Option;
import org.apache.log4j.Logger;
import org.apache.log4j.helpers.Loader;
@@ -23,7 +24,7 @@
// Create a new org.apache.log4j.Category object from the <category> element.
String loggerName = loggerElement.getAttribute(ActionConst.NAME_ATTRIBUTE);
- if(loggerName == null || ActionConst.EMPTY_STR.equals(loggerName)) {
+ if(Option.isEmpty(loggerName)) {
inError = true;
String errorMsg = "No 'name' attribute in element "
+loggerElement.getTagName();
1.1
jakarta-log4j/src/java/org/apache/joran/action/NestComponentIA.java
Index: NestComponentIA.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
import org.apache.log4j.Logger;
import org.apache.log4j.config.PropertySetter;
import org.apache.log4j.helpers.Loader;
import org.apache.log4j.spi.OptionHandler;
import org.w3c.dom.Element;
/**
* @author Ceki Gülcü
*
*/
public class NestComponentIA extends ImplicitAction {
static final Logger logger = Logger.getLogger(NestComponentIA.class);
Object nestedComponent;
int containmentType;
PropertySetter parentBean;
public boolean isApplicable(Element nestedElement, ExecutionContext ec) {
inError = false;
Object o = ec.peekObject();
parentBean = new PropertySetter(o);
String nestedElementTagName = nestedElement.getTagName();
containmentType = parentBean.canContainComponent(nestedElementTagName);
switch (containmentType) {
case PropertySetter.NOT_FOUND:
return false;
case PropertySetter.AS_COLLECTION:
return true;
case PropertySetter.AS_PROPERTY:
return true;
default:
inError= true;
ec.addError("PropertySetter.canContainComponent returned "+containmentType);
return false;
}
}
public void begin(ExecutionContext ec, Element e) {
// inError was reset in isApplicable. It should not be touched here
String className = e.getAttribute(ActionConst.CLASS_ATTRIBUTE);
String tagName = e.getTagName();
if(className == null || ActionConst.EMPTY_STR.equals(className)) {
inError = true;
String errMsg = "No class name attribute in <"+tagName+">";
logger.error(errMsg);
ec.addError(errMsg);
return;
}
try {
logger.debug("About to instantiate component <"+tagName+ "> of type [" +
className + "]");
nestedComponent = Loader.loadClass(className).newInstance();
logger.debug("Pushing component <"+tagName+"> on top of the object stack.");
ec.pushObject(nestedComponent);
} catch (Exception oops) {
inError = true;
String msg = "Could not create component <"+tagName+">.";
logger.error(msg, oops);
ec.addError(msg);
}
}
public void end(ExecutionContext ec, Element e) {
if (inError) {
return;
}
if (nestedComponent instanceof OptionHandler) {
((OptionHandler) nestedComponent).activateOptions();
}
Object o = ec.peekObject();
if (o != nestedComponent) {
logger.warn(
"The object on the top the of the stack is not the component pushed
earlier.");
} else {
logger.warn("Removing component from the object stack");
ec.popObject();
String tagName = e.getTagName();
// Now let us attach the component
switch (containmentType) {
case PropertySetter.AS_PROPERTY:
logger.debug("Setting ["+tagName+"] to parent.");
parentBean.setComponent(tagName, nestedComponent);
break;
case PropertySetter.AS_COLLECTION:
logger.debug("Adding ["+tagName+"] to parent.");
parentBean.addComponent(e.getTagName(), nestedComponent);
break;
}
}
}
public void finish(ExecutionContext ec) {
}
}
1.1
jakarta-log4j/src/java/org/apache/joran/action/ImplicitAction.java
Index: ImplicitAction.java
===================================================================
/*
* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "log4j" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation. For more information on the
* Apache Software Foundation, please see <http://www.apache.org/>.
*
*/
package org.apache.joran.action;
import org.apache.joran.ExecutionContext;
import org.w3c.dom.Element;
/**
* ImplcitActions are like normal (explicit) actions except that are applied
* by the parser when no other pattern applies. Since there can be many implcit
* actions, each action is asked whether it applies in the given context. The
* first impplcit action to respond postively will be applied. See also the
* [EMAIL PROTECTED] #isApplicable} method.
*
* @author Ceki Gülcü
*/
public abstract class ImplicitAction extends Action {
public abstract boolean isApplicable(Element e, ExecutionContext ec);
}
1.5 +29 -6 jakarta-log4j/src/java/org/apache/joran/JoranParser.java
Index: JoranParser.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/JoranParser.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JoranParser.java 10 Sep 2003 16:28:18 -0000 1.4
+++ JoranParser.java 12 Sep 2003 18:24:26 -0000 1.5
@@ -57,6 +57,7 @@
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -65,16 +66,22 @@
static final Logger logger = Logger.getLogger(JoranParser.class);
private RuleStore ruleStore;
private ExecutionContext ec;
-
+ private ArrayList implicitActions;
+
JoranParser(RuleStore rs) {
ruleStore = rs;
ec = new ExecutionContext(this);
+ implicitActions = new ArrayList(3);
}
public ExecutionContext getExecutionContext() {
return ec;
}
+ public void addImplcitAction(ImplicitAction ia) {
+ implicitActions.add(ia);
+ }
+
public void parse(Document document) {
Pattern currentPattern = new Pattern();
Element e = document.getDocumentElement();
@@ -86,19 +93,25 @@
return;
}
+
+ //logger.debug("Node type is "+n.getNodeType()+", name is "+n.getNodeName()+",
value "+n.getNodeValue());
+
+
try {
+ // Element currentElement = (Element) n;
+
currentPattern.push(n.getNodeName());
-
- if (n instanceof Element) {
+ // only print the pattern for ELEMENT NODES
+ if(n.getNodeType() == Node.ELEMENT_NODE) {
logger.debug("pattern is " + currentPattern);
}
-
List applicableActionList = ruleStore.matchActions(currentPattern);
//logger.debug("set of applicable patterns: " + applicableActionList);
if (applicableActionList == null) {
- applicableActionList = lookupImplicitAction(currentPattern);
+ if(n instanceof Element)
+ applicableActionList = lookupImplicitAction((Element)n, ec);
}
if (applicableActionList != null) {
@@ -124,7 +137,17 @@
* action is found, it is returned. Thus, the returned list will have at most
* one element.
*/
- List lookupImplicitAction(Pattern p) {
+ List lookupImplicitAction(Element element, ExecutionContext ec) {
+ int len = implicitActions.size();
+ for(int i = 0; i < len; i++) {
+ ImplicitAction ia = (ImplicitAction) implicitActions.get(i);
+ if(ia.isApplicable(element, ec)) {
+ List actionList = new ArrayList(1);
+ actionList.add(ia);
+ return actionList;
+ }
+
+ }
return null;
}
1.4 +1 -1 jakarta-log4j/src/java/org/apache/joran/RuleStore.java
Index: RuleStore.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/joran/RuleStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RuleStore.java 2 Sep 2003 18:36:29 -0000 1.3
+++ RuleStore.java 12 Sep 2003 18:24:26 -0000 1.4
@@ -56,6 +56,6 @@
public interface RuleStore {
public void addRule(Pattern pattern, Action action);
-
+
public List matchActions(Pattern pattern);
}
1.1 jakarta-log4j/src/java/org/apache/joran/helper/Option.java
Index: Option.java
===================================================================
package org.apache.joran.helper;
/**
*
*
* @author Ceki Gülcü
*/
public class Option {
static final String EMPTY_STR = "";
static public boolean isEmpty(String val) {
return (val == null || EMPTY_STR.equals(val));
}
}
1.4 +7 -6
jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java
Index: PatternParser.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PatternParser.java 10 Jul 2003 17:08:46 -0000 1.3
+++ PatternParser.java 12 Sep 2003 18:24:26 -0000 1.4
@@ -55,6 +55,7 @@
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.helpers.OptionConverter;
+import java.util.HashMap;
import java.util.Hashtable;
@@ -93,10 +94,10 @@
static final int LEVEL_CONVERTER = 2002;
static final int NDC_CONVERTER = 2003;
static final int MESSAGE_CONVERTER = 2004;
- static Hashtable globalRulesRegistry;
+ static HashMap globalRulesRegistry;
static {
- globalRulesRegistry = new Hashtable(17);
+ globalRulesRegistry = new HashMap(17);
globalRulesRegistry.put("c", LoggerPatternConverter.class.getName());
globalRulesRegistry.put("C", ClassNamePatternConverter.class.getName());
globalRulesRegistry.put("F", FileLocationPatternConverter.class.getName());
@@ -122,7 +123,7 @@
PatternConverter tail;
protected FormattingInfo formattingInfo = new FormattingInfo();
protected String pattern;
- Hashtable converterRegistry;
+ HashMap converterRegistry;
static Logger logger = Logger.getLogger("LOG4J."+PatternParser.class.getName());
@@ -437,11 +438,11 @@
formattingInfo.reset();
}
- public Hashtable getConverterRegistry() {
+ public HashMap getConverterRegistry() {
return converterRegistry;
}
- public void setConverterRegistry(Hashtable hashtable) {
- converterRegistry = hashtable;
+ public void setConverterRegistry(HashMap converterRegistry) {
+ this.converterRegistry = converterRegistry;
}
}
1.21 +34 -6 jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java
Index: PatternLayout.java
===================================================================
RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- PatternLayout.java 23 Jun 2003 16:04:25 -0000 1.20
+++ PatternLayout.java 12 Sep 2003 18:24:26 -0000 1.21
@@ -51,6 +51,7 @@
import java.io.IOException;
import java.io.Writer;
+import java.util.HashMap;
import org.apache.log4j.pattern.PatternConverter;
import org.apache.log4j.pattern.PatternParser;
@@ -439,9 +440,11 @@
public static final String TTCC_CONVERSION_PATTERN =
"%r [%t] %p %c %x - %m%n";
- private String pattern;
+ private String conversionPattern;
private PatternConverter head;
+ private HashMap ruleRegistry = null;
+
/**
Constructs a PatternLayout using the DEFAULT_LAYOUT_PATTERN.
@@ -456,34 +459,59 @@
*/
public PatternLayout(String pattern) {
//System.out.println("...PatternLayout ["+pattern+"], "+this);
- this.pattern = pattern;
+ this.conversionPattern = pattern;
head =
createPatternParser(
(pattern == null) ? DEFAULT_CONVERSION_PATTERN : pattern).parse();
}
/**
+ *
+ * Add a new conversion word and associate it with a
+ * [EMAIL PROTECTED] org.apache.log4j.pattern.PatternConverter PatternConverter}
class.
+ *
+ * @param conversionWord New conversion word to accept in conversion patterns
+ * @param converterClass The class name associated with the conversion word
+ * @since 1.3
+ */
+ public void addConversionRule(String conversionWord, String converterClass) {
+ if(ruleRegistry == null) {
+ ruleRegistry = new HashMap(5);
+ }
+ ruleRegistry.put(conversionWord, converterClass);
+ }
+
+ /**
+ * Returns the rule registry specific for this PatternLayout instance.
+ * @since 1.3
+ */
+ public HashMap getRuleRegistry() {
+ return ruleRegistry;
+ }
+
+ /**
Set the <b>ConversionPattern</b> option. This is the string which
controls formatting and consists of a mix of literal content and
conversion specifiers.
*/
public void setConversionPattern(String conversionPattern) {
- pattern = conversionPattern;
- head = createPatternParser(conversionPattern).parse();
+ this.conversionPattern = conversionPattern;
}
/**
Returns the value of the <b>ConversionPattern</b> option.
*/
public String getConversionPattern() {
- return pattern;
+ return conversionPattern;
}
/**
Does not do anything as options become effective
*/
public void activateOptions() {
- // nothing to do.
+ PatternParser patternParser = createPatternParser(conversionPattern);
+ patternParser.setConverterRegistry(ruleRegistry);
+ head = patternParser.parse();
}
/**
1.4 +188 -83
jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java
Index: JoranParserTest.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/tests/src/java/org/apache/joran/JoranParserTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- JoranParserTest.java 11 Sep 2003 17:25:24 -0000 1.3
+++ JoranParserTest.java 12 Sep 2003 18:24:26 -0000 1.4
@@ -1,4 +1,53 @@
/*
+ * ============================================================================
+ * The Apache Software License, Version 1.1
+ * ============================================================================
+ *
+ * Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modifica-
+ * tion, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * 3. The end-user documentation included with the redistribution, if any, must
+ * include the following acknowledgment: "This product includes software
+ * developed by the Apache Software Foundation (http://www.apache.org/)."
+ * Alternately, this acknowledgment may appear in the software itself, if
+ * and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The names "log4j" and "Apache Software Foundation" must not be used to
+ * endorse or promote products derived from this software without prior
+ * written permission. For written permission, please contact
+ * [EMAIL PROTECTED]
+ *
+ * 5. Products derived from this software may not be called "Apache", nor may
+ * "Apache" appear in their name, without prior written permission of the
+ * Apache Software Foundation.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
+ * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * This software consists of voluntary contributions made by many individuals
+ * on behalf of the Apache Software Foundation. For more information on the
+ * Apache Software Foundation, please see <http://www.apache.org/>.
+ *
+ */
+
+/*
* Created on Aug 24, 2003
*
* To change the template for this generated file go to
@@ -6,10 +55,7 @@
*/
package org.apache.joran;
-import java.util.HashMap;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
+import junit.framework.TestCase;
import org.apache.joran.action.ActionConst;
import org.apache.joran.action.AppenderAction;
@@ -17,15 +63,22 @@
import org.apache.joran.action.LayoutAction;
import org.apache.joran.action.LevelAction;
import org.apache.joran.action.LoggerAction;
+import org.apache.joran.action.NestComponentIA;
import org.apache.joran.action.ParamAction;
import org.apache.joran.action.RootLoggerAction;
+
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
+
import org.w3c.dom.Document;
-import junit.framework.TestCase;
+import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
/**
* @author ceki
@@ -34,90 +87,142 @@
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class JoranParserTest extends TestCase {
+ static final Logger logger = Logger.getLogger(JoranParserTest.class);
- final static Logger logger = Logger.getLogger(JoranParserTest.class);
-
- /**
- * Constructor for JoranParserTestCase.
- * @param name
- */
- public JoranParserTest(String name) {
- super(name);
- }
-
- /*
- * @see TestCase#setUp()
- */
- protected void setUp() throws Exception {
- super.setUp();
- Logger root = Logger.getRootLogger();
- root.addAppender(
- new ConsoleAppender(
- new PatternLayout("%r %5p [%t] %c{2} -
%m%n")));
- }
-
- /*
- * @see TestCase#tearDown()
- */
- protected void tearDown() throws Exception {
- super.tearDown();
- LogManager.shutdown();
- }
+ /**
+ * Constructor for JoranParserTestCase.
+ * @param name
+ */
+ public JoranParserTest(String name) {
+ super(name);
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Logger root = Logger.getRootLogger();
+ root.addAppender(
+ new ConsoleAppender(new PatternLayout("%r %5p [%t] %c{2} - %m%n")));
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ LogManager.shutdown();
+ }
public void xtestLoop() throws Exception {
- logger.debug("Starting testLoop");
+ logger.debug("Starting testLoop");
- DocumentBuilderFactory dbf = null;
+ DocumentBuilderFactory dbf = null;
- dbf = DocumentBuilderFactory.newInstance();
+ dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
-
- Document doc = docBuilder.parse("file:input/joran/parser1.xml");
- RuleStore rs = new SimpleRuleStore();
- logger.debug("pattern: "+new Pattern("log4j:configuration/logger"));
- rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
- rs.addRule(new Pattern("log4j:configuration/logger/level"), new
LevelAction());
- rs.addRule(new Pattern("log4j:configuration/root"), new
RootLoggerAction());
- rs.addRule(new Pattern("log4j:configuration/root"), new
RootLoggerAction());
- JoranParser jp = new JoranParser(rs);
- ExecutionContext ec = jp.getExecutionContext();
- HashMap omap = ec.getObjectMap();
- omap.put(ActionConst.APPENDER_BAG, new HashMap());
- ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
- }
-
- public void testLoop2() throws Exception {
- logger.debug("Starting testLoop2");
-
- DocumentBuilderFactory dbf = null;
-
- dbf = DocumentBuilderFactory.newInstance();
-
- DocumentBuilder docBuilder = dbf.newDocumentBuilder();
-
- //inputSource.setSystemId("dummy://log4j.dtd");
-
- Document doc =
docBuilder.parse("file:input/joran/parser2.xml");
- RuleStore rs = new SimpleRuleStore();
- rs.addRule(new Pattern("log4j:configuration/logger"), new
LoggerAction());
- rs.addRule(new Pattern("log4j:configuration/logger/level"),
new LevelAction());
- rs.addRule(new Pattern("log4j:configuration/root"), new
RootLoggerAction());
- rs.addRule(new Pattern("log4j:configuration/logger/appender-ref"),
new AppenderRefAction());
- rs.addRule(new Pattern("log4j:configuration/root/appender-ref"),
new AppenderRefAction());
- rs.addRule(new Pattern("log4j:configuration/appender"), new
AppenderAction());
- rs.addRule(new Pattern("log4j:configuration/appender/layout"), new
LayoutAction());
- rs.addRule(new Pattern("*/param"), new ParamAction());
- JoranParser jp = new JoranParser(rs);
- ExecutionContext ec = jp.getExecutionContext();
- HashMap omap = ec.getObjectMap();
- omap.put(ActionConst.APPENDER_BAG, new HashMap());
- ec.pushObject(LogManager.getLoggerRepository());
- jp.parse(doc);
- }
+ DocumentBuilder docBuilder = dbf.newDocumentBuilder();
+
+ //inputSource.setSystemId("dummy://log4j.dtd");
+ Document doc = docBuilder.parse("file:input/joran/parser1.xml");
+ RuleStore rs = new SimpleRuleStore();
+ logger.debug("pattern: " + new Pattern("log4j:configuration/logger"));
+ rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/logger/level"), new LevelAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root"), new RootLoggerAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root"), new RootLoggerAction());
+
+ JoranParser jp = new JoranParser(rs);
+ ExecutionContext ec = jp.getExecutionContext();
+ HashMap omap = ec.getObjectMap();
+ omap.put(ActionConst.APPENDER_BAG, new HashMap());
+ ec.pushObject(LogManager.getLoggerRepository());
+ jp.parse(doc);
+ }
+ public void xtestLoop2() throws Exception {
+ logger.debug("Starting testLoop2");
+ DocumentBuilderFactory dbf = null;
+
+ dbf = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder docBuilder = dbf.newDocumentBuilder();
+
+ //inputSource.setSystemId("dummy://log4j.dtd");
+ Document doc = docBuilder.parse("file:input/joran/parser2.xml");
+ RuleStore rs = new SimpleRuleStore();
+ rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/logger/level"), new LevelAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root"), new RootLoggerAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root/level"), new LevelAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/logger/appender-ref"),
+ new AppenderRefAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root/appender-ref"),
+ new AppenderRefAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/appender"), new AppenderAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/appender/layout"), new LayoutAction());
+ rs.addRule(new Pattern("*/param"), new ParamAction());
+
+ JoranParser jp = new JoranParser(rs);
+ ExecutionContext ec = jp.getExecutionContext();
+ HashMap omap = ec.getObjectMap();
+ omap.put(ActionConst.APPENDER_BAG, new HashMap());
+ ec.pushObject(LogManager.getLoggerRepository());
+ jp.parse(doc);
+ }
+
+ public void testLoop3() throws Exception {
+ logger.debug("Starting testLoop3");
+
+ DocumentBuilderFactory dbf = null;
+
+ dbf = DocumentBuilderFactory.newInstance();
+
+ DocumentBuilder docBuilder = dbf.newDocumentBuilder();
+
+ //inputSource.setSystemId("dummy://log4j.dtd");
+ Document doc = docBuilder.parse("file:input/joran/parser3.xml");
+ RuleStore rs = new SimpleRuleStore();
+ rs.addRule(new Pattern("log4j:configuration/logger"), new LoggerAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/logger/level"), new LevelAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root"), new RootLoggerAction());
+ //rs.addRule(
+ //new Pattern("log4j:configuration/root/level"), new LevelAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/logger/appender-ref"),
+ new AppenderRefAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/root/appender-ref"),
+ new AppenderRefAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/appender"), new AppenderAction());
+ rs.addRule(
+ new Pattern("log4j:configuration/appender/layout"), new LayoutAction());
+ rs.addRule(new Pattern("*/param"), new ParamAction());
+
+ JoranParser jp = new JoranParser(rs);
+ jp.addImplcitAction(new NestComponentIA());
+
+ ExecutionContext ec = jp.getExecutionContext();
+ HashMap omap = ec.getObjectMap();
+ omap.put(ActionConst.APPENDER_BAG, new HashMap());
+ ec.pushObject(LogManager.getLoggerRepository());
+ logger.debug("About to parse doc");
+ jp.parse(doc);
+ }
}
1.8 +3 -2
jakarta-log4j/tests/src/java/org/apache/log4j/MinimumTestCase.java
Index: MinimumTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/MinimumTestCase.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- MinimumTestCase.java 13 May 2003 16:33:15 -0000 1.7
+++ MinimumTestCase.java 12 Sep 2003 18:24:26 -0000 1.8
@@ -99,7 +99,8 @@
Transformer.transform(
"output/simple", FILTERED,
- new Filter[] { new LineNumberFilter(), new SunReflectFilter() });
+ new Filter[] { new LineNumberFilter(), new SunReflectFilter(),
+ new JunitTestRunnerFilter() });
assertTrue(Compare.compare(FILTERED, "witness/simple"));
}
@@ -119,7 +120,7 @@
"output/ttcc", FILTERED,
new Filter[] {
cf1, new LineNumberFilter(), new AbsoluteDateAndTimeFilter(),
- new SunReflectFilter()
+ new SunReflectFilter(), new JunitTestRunnerFilter()
});
assertTrue(Compare.compare(FILTERED, "witness/ttcc"));
1.3 +1 -10
jakarta-log4j/tests/src/java/org/apache/log4j/helpers/BoundedFIFOTestCase.java
Index: BoundedFIFOTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/helpers/BoundedFIFOTestCase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- BoundedFIFOTestCase.java 13 May 2003 16:33:16 -0000 1.2
+++ BoundedFIFOTestCase.java 12 Sep 2003 18:24:26 -0000 1.3
@@ -263,14 +263,5 @@
}
}
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new BoundedFIFOTestCase("test1"));
- suite.addTest(new BoundedFIFOTestCase("test2"));
- suite.addTest(new BoundedFIFOTestCase("testResize1"));
- suite.addTest(new BoundedFIFOTestCase("testResize2"));
- suite.addTest(new BoundedFIFOTestCase("testResize3"));
-
- return suite;
- }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]