You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by ce...@apache.org on 2004/05/12 21:39:14 UTC
cvs commit: logging-log4j/src/java/org/apache/log4j/joran JoranConfigurator.java
ceki 2004/05/12 12:39:14
Modified: src/java/org/apache/log4j/spi LocationInfo.java
LoggingEvent.java
tests/src/java/org/apache/log4j/spi LocationInfoTest.java
src/java/org/apache/log4j/joran JoranConfigurator.java
Log:
- Fixes to LocationInfoTest. (a little testing goes a long way..) this should keep gump happy (at last).
- Added new doConfigure method to JoranConfigurator.
Revision Changes Path
1.20 +1 -1 logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java
Index: LocationInfo.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LocationInfo.java,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -r1.19 -r1.20
--- LocationInfo.java 10 May 2004 19:11:50 -0000 1.19
+++ LocationInfo.java 12 May 2004 19:39:14 -0000 1.20
@@ -127,7 +127,7 @@
s = sw.toString();
sw.getBuffer().setLength(0);
}
-
+
//System.out.println("s is ["+s+"].");
int ibegin;
1.60 +1 -0 logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
Index: LoggingEvent.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- LoggingEvent.java 12 May 2004 15:39:02 -0000 1.59
+++ LoggingEvent.java 12 May 2004 19:39:14 -0000 1.60
@@ -266,6 +266,7 @@
}
this.timeStamp = timeStamp;
+ sequenceNumber = sequenceCount++;
}
1.3 +30 -19 logging-log4j/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java
Index: LocationInfoTest.java
===================================================================
RCS file: /home/cvs/logging-log4j/tests/src/java/org/apache/log4j/spi/LocationInfoTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- LocationInfoTest.java 12 May 2004 15:39:04 -0000 1.2
+++ LocationInfoTest.java 12 May 2004 19:39:14 -0000 1.3
@@ -1,9 +1,19 @@
/*
- * Created on Dec 6, 2003
+ * Copyright 1999,2004 The Apache Software Foundation.
*
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
+
package org.apache.log4j.spi;
import org.apache.log4j.BasicConfigurator;
@@ -14,10 +24,11 @@
import junit.framework.TestCase;
/**
- * @author ceki
- *
- * To change the template for this generated type comment go to
- * Window>Preferences>Java>Code Generation>Code and Comments
+ *
+ * Very simple test verifying that LocationInfo extraction works, at least in
+ * simple cases.
+ *
+ * @author Ceki
*/
public class LocationInfoTest extends TestCase {
@@ -55,21 +66,21 @@
Throwable t1 = new Throwable();
Throwable t2 = new Throwable();
- LoggingEvent le = new LoggingEvent();
- le.setLogger(logger);
- le.setTimeStamp(System.currentTimeMillis());
- le.setLevel(Level.DEBUG);
- le.setMessage("toto");
+ LoggingEvent le = new LoggingEvent("org.apache.log4j.spi.LoggingEvent", logger, Level.DEBUG,
+ "toto", null);
+
+ // line extraction is done from on line 74 (following line)
+ LocationInfo li = le.getLocationInformation();
- LocationInfo l1 = le.getLocationInformation();
-
- logger.debug("classname: "+ l1.getClassName());
- logger.debug("filename: "+ l1.getFileName());
- logger.debug("classname: "+ l1.getClassName());
- logger.debug("filename: "+ l1.getFileName());
+ if(li == LocationInfo.NA_LOCATION_INFO) {
+ fail("For regular events, location info should not be LocationInfo.NA_LOCATION_INFO ");
+ }
- //logger.error("toto", t1);
+ assertEquals(this.getClass().getName(), li.getClassName());
+ assertEquals("LocationInfoTest.java", li.getFileName());
+ assertEquals("74", li.getLineNumber());
+ assertEquals("testEqualsObject", li.getMethodName());
/*ThrowableInformation te1 = new ThrowableInformation(e1);
ThrowableInformation te2 = new ThrowableInformation(e2);
1.5 +53 -42 logging-log4j/src/java/org/apache/log4j/joran/JoranConfigurator.java
Index: JoranConfigurator.java
===================================================================
RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/joran/JoranConfigurator.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JoranConfigurator.java 12 May 2004 15:39:04 -0000 1.4
+++ JoranConfigurator.java 12 May 2004 19:39:14 -0000 1.5
@@ -13,9 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.apache.log4j.joran;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParser;
+import javax.xml.parsers.SAXParserFactory;
+
import org.apache.joran.ErrorItem;
import org.apache.joran.ExecutionContext;
import org.apache.joran.Interpreter;
@@ -23,7 +32,6 @@
import org.apache.joran.RuleStore;
import org.apache.joran.action.ParamAction;
import org.apache.joran.helper.SimpleRuleStore;
-
import org.apache.log4j.helpers.LogLog;
import org.apache.log4j.joran.action.ActionConst;
import org.apache.log4j.joran.action.AppenderAction;
@@ -37,20 +45,8 @@
import org.apache.log4j.joran.action.RootLoggerAction;
import org.apache.log4j.spi.Configurator;
import org.apache.log4j.spi.LoggerRepository;
-
import org.xml.sax.SAXException;
-import java.io.IOException;
-import java.io.InputStream;
-
-import java.net.URL;
-
-import java.util.HashMap;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.parsers.SAXParser;
-import javax.xml.parsers.SAXParserFactory;
-
/**
* @author ceki
@@ -58,7 +54,8 @@
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
-public class JoranConfigurator implements Configurator {
+public class JoranConfigurator
+ implements Configurator {
Interpreter joranInterpreter;
public JoranConfigurator() {
@@ -82,45 +79,60 @@
}
}
+
+ /**
+ * Configure a repository from a configuration file passed as parameter.
+ */
+ public void doConfigure(String filename, LoggerRepository repository) {
+ FileInputStream fis = null;
+ ExecutionContext ec = joranInterpreter.getExecutionContext();
+ ec.pushObject(repository);
+ LogLog.info("in JoranConfigurator doConfigure "+filename);
+ try {
+ fis = new FileInputStream(filename);
+ doConfigure(fis, repository);
+ } catch (IOException ioe) {
+ String errMsg = "Could not open [" + filename + "].";
+ LogLog.error(errMsg, ioe);
+ ec.addError(new ErrorItem(errMsg, ioe));
+ } finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (java.io.IOException e) {
+ LogLog.error("Could not close [" + filename + "].", e);
+ }
+ }
+ }
+ }
+
+
protected void selfInitialize() {
RuleStore rs = new SimpleRuleStore();
rs.addRule(new Pattern("log4j:configuration"), new ConfigurationAction());
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("log4j:configuration/appender/layout/conversionRule"),
- new ConversionRuleAction());
- rs.addRule(
- new Pattern("log4j:configuration/plugin"), new PluginAction());
+ 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("log4j:configuration/appender/layout/conversionRule"), new ConversionRuleAction());
+ rs.addRule(new Pattern("log4j:configuration/plugin"), new PluginAction());
rs.addRule(new Pattern("*/param"), new ParamAction());
- Interpreter jp = new Interpreter(rs);
- ExecutionContext ec = jp.getExecutionContext();
+ joranInterpreter = new Interpreter(rs);
+ ExecutionContext ec = joranInterpreter.getExecutionContext();
HashMap omap = ec.getObjectMap();
omap.put(ActionConst.APPENDER_BAG, new HashMap());
}
+
public void doConfigure(InputStream in, LoggerRepository repository) {
ExecutionContext ec = joranInterpreter.getExecutionContext();
-
ec.pushObject(repository);
-
String errMsg;
try {
@@ -135,8 +147,7 @@
ec.addError(new ErrorItem(errMsg, pce));
} catch (IOException ie) {
errMsg = "I/O error occured while parsing xml file";
- ec.addError(
- new ErrorItem("Parser configuration error occured", ie));
+ ec.addError(new ErrorItem("Parser configuration error occured", ie));
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org