You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2022/02/25 18:19:23 UTC
[daffodil] branch main updated: Change output of dfdlx:trace from stderr to the logger
This is an automated email from the ASF dual-hosted git repository.
slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git
The following commit(s) were added to refs/heads/main by this push:
new 90782a2 Change output of dfdlx:trace from stderr to the logger
90782a2 is described below
commit 90782a21879df7994b49cb2120b2bbffacb4ce73
Author: U-COLUMBIA\arevello <ar...@N12157207.columbia.tresys.com>
AuthorDate: Tue Feb 22 16:51:12 2022 -0500
Change output of dfdlx:trace from stderr to the logger
dfdlx:trace now outputs to the info level of the logger instead of the previous stderr. A CLI parsing test was added to demonstrate the feature
DAFFODIL-2575
---
.../org/apache/daffodil/CLI/trace_input.dfdl.xsd | 56 ++++++++++++++++++++++
.../apache/daffodil/parsing/TestCLIParsing.scala | 23 +++++++++
.../org/apache/daffodil/dpath/DFDLXFunctions.scala | 3 +-
3 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/trace_input.dfdl.xsd b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/trace_input.dfdl.xsd
new file mode 100644
index 0000000..758cdce
--- /dev/null
+++ b/daffodil-cli/src/it/resources/org/apache/daffodil/CLI/trace_input.dfdl.xsd
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<xs:schema
+ targetNamespace="http://example.com"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
+ xmlns:ex="http://example.com"
+ xmlns="http://example.com"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
+ elementFormDefault="unqualified">
+
+ <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/" >
+ <dfdl:format ref="ex:GeneralFormat" representation="text" terminator="" />
+ </xs:appinfo>
+ </xs:annotation>
+
+ <xs:element name="output">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence dfdl:hiddenGroupRef="hidden_message" />
+ <xs:element name="message" type="xs:string" dfdl:inputValueCalc="{
+ if (dfdlx:trace(../Hidden_Value eq '0', 'value')) then 'hello'
+ else fn:error('Unrecognized value')}" dfdl:terminator=""/>
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:group name="hidden_message">
+ <xs:sequence>
+ <xs:element name="Hidden_Value" type="xs:string" dfdl:length="1" dfdl:lengthKind="explicit" dfdl:outputValueCalc="{
+ if (dfdlx:trace(../message eq 'hello', 'value')) then '0'
+ else fn:error('Unrecognized value')}"
+ />
+ </xs:sequence>
+ </xs:group>
+</xs:schema>
diff --git a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
index 1ea308d..38ba43c 100644
--- a/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
+++ b/daffodil-cli/src/it/scala/org/apache/daffodil/parsing/TestCLIParsing.scala
@@ -1319,4 +1319,27 @@ class TestCLIparsing {
}
+ @Test def test_2575_DFDLX_Trace_output(): Unit = {
+
+ val schemaFile = Util.daffodilPath("daffodil-cli/src/it/resources/org/apache/daffodil/CLI/trace_input.dfdl.xsd")
+ val testSchemaFile = if (Util.isWindows) Util.cmdConvert(schemaFile) else schemaFile
+
+ val shell = Util.start("")
+
+ try{
+
+ val cmd = String.format(Util.echoN("0") + "| %s -v parse -r output -s %s ", Util.binPath, testSchemaFile)
+
+ shell.sendLine(cmd)
+
+ //show the log is happening
+ shell.expectIn(1,contains("dfdlx:trace"))
+
+ Util.expectExitCode(ExitCode.Success, shell)
+
+ } finally {
+ shell.close()
+ }
+ }
+
}
diff --git a/daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/DFDLXFunctions.scala b/daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/DFDLXFunctions.scala
index bb29b26..70b02ea 100644
--- a/daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/DFDLXFunctions.scala
+++ b/daffodil-runtime1/src/main/scala/org/apache/daffodil/dpath/DFDLXFunctions.scala
@@ -33,6 +33,7 @@ import org.apache.daffodil.util.Maybe.One
import passera.unsigned.{UByte, UInt, ULong, UShort}
import org.apache.daffodil.infoset.DataValue.DataValueLong
import org.apache.daffodil.infoset.DataValue.DataValueDouble
+import org.apache.daffodil.util.Logger
/**
* This is the "logical" shift left.
@@ -185,7 +186,7 @@ case class DFDLXTrace(recipe: CompiledDPath, msg: String)
}
case other: DINode => other.namedQName.toString
}
- System.err.println("trace " + msg + ":" + nodeString)
+ Logger.log.info(s"dfdlx:trace ${msg} : ${nodeString}")
}
// This is toXML for the case class object, not the infoset node it is