Skip to content
Permalink
Browse files

Support log attribute on cx:message to send message to the log.

  • Loading branch information
ndw committed Sep 15, 2014
1 parent 1a79ba4 commit b829745e9a4ef441199ba55ceaa312d7001d34b4
Showing with 24 additions and 1 deletion.
  1. +1 −0 resources/etc/extension-library.xml
  2. +23 −1 src/com/xmlcalabash/extensions/Message.java
@@ -54,6 +54,7 @@
<p:declare-step type="cx:message">
<p:input port="source" sequence="true"/>
<p:output port="result" sequence="true"/>
<p:option name="log"/>
<p:option name="message" required="true"/>
</p:declare-step>

@@ -4,6 +4,7 @@
import com.xmlcalabash.io.WritablePipe;
import com.xmlcalabash.core.XProcRuntime;

import com.xmlcalabash.model.RuntimeValue;
import com.xmlcalabash.util.MessageFormatter;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XdmNode;
@@ -23,6 +24,7 @@

public class Message extends DefaultStep {
private static final QName _message = new QName("","message");
private static final QName _log = new QName("","log");
private ReadablePipe source = null;
private WritablePipe result = null;

@@ -50,7 +52,27 @@ public void run() throws SaxonApiException {
super.run();

String message = getOption(_message).getString();
System.err.println("Message: " + message);
RuntimeValue loglevel = getOption(_log);

if (loglevel == null) {
System.err.println("Message: " + message);
} else {
String level = loglevel.getString();
if ("error".equals(level)) {
logger.error(message);
} else if ("warn".equals(level)) {
logger.warn(message);
} else if ("info".equals(level)) {
logger.info(message);
} else if ("debug".equals(level)) {
logger.debug(message);
} else if ("trace".equals(level)) {
logger.trace(message);
} else {
logger.warn("Unrecognized cx:message log level: " + level);
logger.warn(message);
}
}

while (source.moreDocuments()) {
XdmNode doc = source.read();

0 comments on commit b829745

Please sign in to comment.
You can’t perform that action at this time.