Permalink
Browse files

Convert to slf4j for logging (backed by log4j2 locally), add test sui…

…te so it can be run locally
  • Loading branch information...
ndw committed Sep 11, 2014
1 parent 793ca03 commit ce9b07d09d05c70c5abfa2bc5d79ce7ff3747776
Showing 988 changed files with 35,860 additions and 722 deletions.
View
@@ -84,7 +84,7 @@
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
- <pathelement location="${ant.library.dir}/ant.jar"/>
+ <pathelement location="${lib.dir}"/>
</path>
<path id="full.classpath">
@@ -179,11 +179,15 @@
<copy todir="${build.dir}/etc">
<fileset dir="resources/etc">
<exclude name="install-proto.xsl"/>
+ <exclude name="log4j2.xml"/>
</fileset>
</copy>
<copy todir="${build.dir}/com">
<fileset dir="resources/com"/>
</copy>
+ <copy todir="${build.dir}">
+ <fileset file="resources/etc/log4j2.xml"/>
+ </copy>
</target>
<target name="jar" depends="compile">
@@ -535,6 +539,9 @@ java -Xmx1024m -jar %INSTALL_PATH/calabash.jar "$@"
<copy todir="${install.dir}/lib">
<fileset file="lib/commons*.jar"/>
<fileset file="lib/http*.jar"/>
+ <fileset file="lib/log4j*.jar"/>
+ <fileset file="lib/slf4j*.jar"/>
+ <fileset file="lib/jcl-over-slf4j*.jar"/>
<fileset file="lib/xmlresolver.jar"/>
<fileset file="lib/saxon9he.jar"/>
</copy>
@@ -562,7 +569,7 @@ java -Xmx1024m -jar %INSTALL_PATH/calabash.jar "$@"
<echo message="CLASSPATH=${myclasspath}"/>
-->
<echo>Running test...</echo>
- <junit printsummary="yes" haltonfailure="no">
+ <junit printsummary="yes" haltonfailure="yes" fork="yes">
<classpath refid="test.classpath"/>
<jvmarg value="-Xmx1024m"/>
<formatter type="plain" usefile="false"/>
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Default log4j2 configuration file for XML Calabash -->
+<Configuration status="warn">
+ <Appenders>
+ <Console name="Console" target="SYSTEM_ERR">
+ <PatternLayout pattern="%-5level: %msg%n" />
+ </Console>
+ </Appenders>
+ <Loggers>
+ <Logger name="com.xmlcalabash" level="info">
+ <AppenderRef ref="Console"/>
+ </Logger>
+ <Root level="warn">
+ <AppenderRef ref="Console" />
+ </Root>
+ </Loggers>
+</Configuration>
@@ -42,7 +42,6 @@
import java.util.Map;
import java.util.Stack;
import java.util.Vector;
-import java.util.logging.Logger;
import javax.xml.transform.URIResolver;
import javax.xml.transform.sax.SAXSource;
@@ -68,6 +67,8 @@
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.client.StandardHttpRequestRetryHandler;
import org.apache.http.impl.client.SystemDefaultHttpClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
@@ -113,7 +114,7 @@
* @author ndw
*/
public class XProcRuntime {
- protected Logger logger = Logger.getLogger("com.xmlcalabash");
+ protected Logger logger = LoggerFactory.getLogger(XProcRuntime.class);
private Processor processor = null;
private Parser parser = null;
private XProcURIResolver uriResolver = null;
@@ -135,7 +136,6 @@
private boolean useXslt10 = false;
private boolean htmlSerializer = false;
private XProcData xprocData = null;
- private Logger log = null;
private XProcMessageListener msgListener = null;
private PipelineLibrary standardLibrary = null;
private XLibrary xStandardLibrary = null;
@@ -187,8 +187,6 @@ public XProcRuntime(XProcConfiguration config) {
processor.registerExtensionFunction(xf);
}
- log = Logger.getLogger(this.getClass().getName());
-
Configuration saxonConfig = processor.getUnderlyingConfiguration();
uriResolver = new XProcURIResolver(this);
saxonConfig.setURIResolver(uriResolver);
@@ -233,17 +231,17 @@ public XProcRuntime(XProcConfiguration config) {
for (String className : config.extensionFunctions) {
try {
Object def = Class.forName(className).newInstance();
- finer(null, null, "Instantiated: " + className);
+ logger.trace("Instantiated: " + className);
if (def instanceof ExtensionFunctionDefinition)
processor.registerExtensionFunction((ExtensionFunctionDefinition) def);
else if (def instanceof ExtensionFunction)
processor.registerExtensionFunction((ExtensionFunction) def);
else
- info(null, null, "Failed to instantiate extension function " + className + " because that class implements neither ExtensionFunction nor ExtensionFunctionDefinition.");
+ logger.info("Failed to instantiate extension function " + className + " because that class implements neither ExtensionFunction nor ExtensionFunctionDefinition.");
} catch (NoClassDefFoundError ncdfe) {
- info(null, null, "Failed to instantiate extension function: " + className);
+ logger.info("Failed to instantiate extension function: " + className);
} catch (Exception e) {
- info(null, null, "Failed to instantiate extension function: " + className);
+ logger.info("Failed to instantiate extension function: " + className);
}
}
@@ -259,7 +257,6 @@ public XProcRuntime(XProcRuntime runtime) {
staticBaseURI = runtime.staticBaseURI;
useXslt10 = runtime.useXslt10;
htmlSerializer = runtime.htmlSerializer;
- log = runtime.log;
msgListener = runtime.msgListener;
standardLibrary = runtime.standardLibrary;
xStandardLibrary = runtime.xStandardLibrary;
@@ -932,18 +929,6 @@ public void info(XProcRunnable step, XdmNode node, String message) {
msgListener.info(step, node, message);
}
- public void fine(XProcRunnable step, XdmNode node, String message) {
- msgListener.fine(step, node, message);
- }
-
- public void finer(XProcRunnable step, XdmNode node, String message) {
- msgListener.finer(step, node, message);
- }
-
- public void finest(XProcRunnable step, XdmNode node, String message) {
- msgListener.finest(step, node, message);
- }
-
// ===========================================================
private Stack<XStep> runningSteps = new Stack<XStep>();
@@ -890,6 +890,7 @@ public void setURIResolver(Class<? extends URIResolver> uriResolver) {
*
* @param libraries the configured Resources object represented as {@code <library>}.
*/
+ @SuppressWarnings("unchecked")
public void addConfiguredLibrary(UseableResources libraries) {
if (!libraries.shouldUse()) {
log("Skipping library as it is configured to be unused.", Project.MSG_DEBUG);
@@ -1229,6 +1230,7 @@ public void execute() {
* @param outputResources the map of output ports to resources
* @throws BuildException if the processing fails.
*/
+ @SuppressWarnings("unchecked")
private void process(Map<String, List<TypedResource>> inputResources, Map<String, Union> outputResources) throws BuildException {
if (!force && (pipelineResource != null)) {
long pipelineLastModified = pipelineResource.getLastModified();
@@ -1348,7 +1350,7 @@ protected void handleError(Throwable ex) {
throw new BuildException(ex);
} else {
log("Caught an exception: " + ex, Project.MSG_WARN);
- ex.printStackTrace(new PrintStream(new LogOutputStream(this, Project.MSG_VERBOSE)));
+ log(ex, Project.MSG_DEBUG);
}
}
@@ -31,7 +31,6 @@
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Logger;
import com.xmlcalabash.core.XProcConfiguration;
import com.xmlcalabash.core.XProcConstants;
@@ -56,6 +55,8 @@
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmSequenceIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.xml.sax.InputSource;
import static com.xmlcalabash.core.XProcConstants.c_data;
@@ -70,7 +71,7 @@
private static QName _code = new QName("code");
private static int exitStatus = 0;
private XProcRuntime runtime = null;
- private Logger logger = Logger.getLogger(this.getClass().getName());
+ private Logger logger = LoggerFactory.getLogger(Main.class);
private boolean debug = false;
/**
@@ -104,9 +105,9 @@ public void run(String[] args) throws IOException {
} catch (XProcException err) {
exitStatus = 1;
if (err.getErrorCode() != null) {
- error(logger, null, errorMessage(err.getErrorCode()), err.getErrorCode());
+ logger.error(errorMessage(err.getErrorCode()));
} else {
- error(logger, null, err.toString(), null);
+ logger.error(err.getMessage());
}
Throwable cause = err.getCause();
@@ -115,22 +116,18 @@ public void run(String[] args) throws IOException {
}
if (cause != null) {
- error(logger, null, "Underlying exception: " + cause, null);
+ logger.error("Underlying exception: " + cause.getMessage());
}
- if (debug) {
- err.printStackTrace();
- }
+ logger.debug(err.getMessage(), err);
} catch (Exception err) {
exitStatus = 1;
- error(logger, null, "Pipeline failed: " + err.toString(), null);
+ logger.error("Pipeline failed: " + err.getMessage());
if (err.getCause() != null) {
Throwable cause = err.getCause();
- error(logger, null, "Underlying exception: " + cause, null);
- }
- if (debug) {
- err.printStackTrace();
+ logger.error("Underlying exception: " + cause.getMessage());
}
+ logger.debug(err.getMessage(), err);
} finally {
// Here all memory should be freed by the next gc, right?
if (runtime != null) {
@@ -345,16 +342,16 @@ boolean run(UserArgs userArgs, XProcConfiguration config) throws SaxonApiExcepti
}
if ((output == null) || ((output.getKind() == OUTPUT_STREAM) && System.out.equals(output.getOutputStream()))) {
- finest(logger, null, "Copy output from " + port + " to stdout");
+ logger.trace("Copy output from " + port + " to stdout");
} else {
switch (output.getKind()) {
case URI:
- finest(logger, null, "Copy output from " + port + " to " + output.getUri());
+ logger.trace("Copy output from " + port + " to " + output.getUri());
break;
case OUTPUT_STREAM:
String outputStreamClassName = output.getOutputStream().getClass().getName();
- finest(logger, null, "Copy output from " + port + " to " + outputStreamClassName + " stream");
+ logger.trace("Copy output from " + port + " to " + outputStreamClassName + " stream");
break;
default:
@@ -479,49 +476,4 @@ private String errorMessage(QName code) {
}
return "Unknown error";
}
-
- // ===========================================================
- // Logging methods repeated here so that they don't rely
- // on the XProcRuntime constructor succeeding.
-
- private String message(XdmNode node, String message) {
- String baseURI = "(unknown URI)";
- int lineNumber = -1;
-
- if (node != null) {
- baseURI = node.getBaseURI().toASCIIString();
- lineNumber = node.getLineNumber();
- return baseURI + ":" + lineNumber + ": " + message;
- } else {
- return message;
- }
-
- }
-
- public void error(Logger logger, XdmNode node, String message, QName code) {
- logger.severe(message(node, message));
- }
-
- public void warning(Logger logger, XdmNode node, String message) {
- logger.warning(message(node, message));
- }
-
- public void info(Logger logger, XdmNode node, String message) {
- logger.info(message(node, message));
- }
-
- public void fine(Logger logger, XdmNode node, String message) {
- logger.fine(message(node, message));
- }
-
- public void finer(Logger logger, XdmNode node, String message) {
- logger.finer(message(node, message));
- }
-
- public void finest(Logger logger, XdmNode node, String message) {
- logger.finest(message(node, message));
- }
-
- // ===========================================================
-
}
Oops, something went wrong.

0 comments on commit ce9b07d

Please sign in to comment.