You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by GitBox <gi...@apache.org> on 2022/04/01 18:40:11 UTC
[GitHub] [daffodil] stevedlawrence commented on a change in pull request #781: Daffodil 2643 tdml logs
stevedlawrence commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840826099
##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLAppender.scala
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package org.apache.daffodil.tdml
+
+import org.apache.logging.log4j.core.appender.AbstractAppender
+import org.apache.logging.log4j.core.filter.ThresholdFilter
+import org.apache.logging.log4j.core.LogEvent
+import org.apache.logging.log4j.core.Filter.Result
+import org.apache.logging.log4j.Level
+import org.apache.daffodil.api.Diagnostic
+import org.apache.daffodil.util.Maybe
+import org.apache.daffodil.util.Maybe._
+import org.apache.logging.log4j.core.config.plugins.{Plugin, PluginFactory}
+
+@Plugin(
+ name="CustomAppender",
+ category="Core",
+ elementType="appender"
+)
+class TDMLAppender
+ extends AbstractAppender ("org.apache.daffodil.tdml", ThresholdFilter.createFilter(Level.INFO, Result.ACCEPT, Result.DENY), null, false, null) {
Review comment:
Is there any value in making the log level configurable, maybe with something like:
```xml
<tdml:logs level="info">
....
</tdml:logs>
```
I imagine most tests only care about warnings logs and so would be a reasonable default, but this would allow bumping up the level to info/debug/etc for tests that are checking for something very specific?
##########
File path: daffodil-tdml-processor/src/test/resources/test/tdml/testLogs.tdml
##########
@@ -0,0 +1,195 @@
+<?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.
+-->
+
+<tdml:testSuite suiteName="tdml logs"
+ xmlns:tdml="http://www.ibm.com/xmlns/dfdl/testData"
+ xmlns:dfdlx="http://www.ogf.org/dfdl/dfdl-1.0/extensions"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:dfdl="http://www.ogf.org/dfdl/dfdl-1.0/"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
+ xmlns:ex="http://example.com"
+ xmlns:fn="http://www.w3.org/2005/xpath-functions">
+ <tdml:defineSchema name="causesLogs" elementFormDefault="unqualified">
+ <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="implicit"/>
+ <xs:element name="output">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence dfdl:hiddenGroupRef="hidden_message" />
+ <xs:element name="message" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="5" 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>
+ </tdml:defineSchema>
+
+ <tdml:defineSchema name="causesLogs2" elementFormDefault="unqualified">
+ <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="implicit"/>
+ <xs:element name="output">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence dfdl:hiddenGroupRef="hidden_message" />
+ <xs:element name="message" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="5" 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>
+ </tdml:defineSchema>
+
+ <tdml:defineSchema name="causesWarningsAndLogs" elementFormDefault="unqualified">
+ <xs:include schemaLocation="org/apache/daffodil/xsd/DFDLGeneralFormat.dfdl.xsd"/>
+ <dfdl:format ref="ex:GeneralFormat" lengthKind="explicit" occursCountKind="implicit"/>
+ <xs:element name="output" dfdl:lengthKind="implicit">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence dfdl:hiddenGroupRef="hidden_message" />
+ <xs:element name="message" type="xs:string" dfdl:lengthKind="explicit" dfdl:length="5" dfdl:inputValueCalc="{
+ if (dfdlx:trace(../Hidden_Value eq '0', 'value')) then 'hello'
+ else fn:error('Unrecognized value')}" dfdl:terminator="" />
+ <xs:element name="AmbgElt" type="xs:string" dfdl:length='1' />
+ <xs:element name="B" type="xs:string" dfdl:length="1" />
+ <xs:element name="AmbgElt" type="xs:string" dfdl:length="1" minOccurs="0"/>
+ <xs:sequence>
+ <xs:annotation>
+ <xs:appinfo source="http://www.ogf.org/dfdl/">
+ <dfdl:assert>{ ./AmbgElt eq '1' }</dfdl:assert>
+ </xs:appinfo>
+ </xs:annotation>
+ </xs:sequence>
+ </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>
+ </tdml:defineSchema>
+
+ <tdml:parserTestCase name="logWhenExpectingSuccess" root="output" model="causesLogs">
+ <tdml:document><![CDATA[0]]></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:output>
+ <message>hello</message>
+ </ex:output>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="logWhenExpectingError" root="output" model="causesLogs">
+ <tdml:document><![CDATA[00]]></tdml:document>
+ <tdml:errors>
+ <tdml:error>Left over data</tdml:error>
+ </tdml:errors>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:parserTestCase>
+
+ <tdml:parserTestCase name="logWhenExpectingWarning" root="output" model="causesWarningsAndLogs">
+ <tdml:document><![CDATA[013]]></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:output>
+ <message>hello</message>
+ <AmbgElt>1</AmbgElt>
+ <B>3</B>
+ </ex:output>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:warnings>
+ <tdml:warning>Schema definition warning</tdml:warning>
+ </tdml:warnings>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:parserTestCase>
+
+ <tdml:unparserTestCase name="unparserLogWhenExpectingSuccess" root="output" model="causesLogs">
+ <tdml:document><![CDATA[0]]></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:output>
+ <message>hello</message>
+ </ex:output>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:unparserTestCase>
+
+ <tdml:unparserTestCase name="unparserLogWhenExpectingError" root="output" model="causesLogs">
+ <tdml:document><![CDATA[00]]></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:output>
+ <message>hello</message>
+ </ex:output>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:errors>
+ <tdml:error>output data length</tdml:error>
+ </tdml:errors>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:unparserTestCase>
+
+ <tdml:unparserTestCase name="unparserLogWhenExpectingWarning" root="output" model="causesWarningsAndLogs">
+ <tdml:document><![CDATA[013]]></tdml:document>
+ <tdml:infoset>
+ <tdml:dfdlInfoset>
+ <ex:output>
+ <message>hello</message>
+ <AmbgElt>1</AmbgElt>
+ <B>3</B>
+ </ex:output>
+ </tdml:dfdlInfoset>
+ </tdml:infoset>
+ <tdml:warnings>
+ <tdml:warning>Schema definition warning</tdml:warning>
+ </tdml:warnings>
+ <tdml:logs>
+ <tdml:log>dfdlx:trace</tdml:log>
+ </tdml:logs>
+ </tdml:unparserTestCase>
+</tdml:testSuite>
Review comment:
Tests look nice. I wonder if there are any CLI tests that can be removed now that this has the ability to check logs? Previously that could only be done via the CLI.
##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLAppender.scala
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.
+ */
+
+package org.apache.daffodil.tdml
+
+import org.apache.logging.log4j.core.appender.AbstractAppender
+import org.apache.logging.log4j.core.filter.ThresholdFilter
+import org.apache.logging.log4j.core.LogEvent
+import org.apache.logging.log4j.core.Filter.Result
+import org.apache.logging.log4j.Level
+import org.apache.daffodil.api.Diagnostic
+import org.apache.daffodil.util.Maybe
+import org.apache.daffodil.util.Maybe._
+import org.apache.logging.log4j.core.config.plugins.{Plugin, PluginFactory}
+
+@Plugin(
+ name="CustomAppender",
+ category="Core",
+ elementType="appender"
+)
+class TDMLAppender
+ extends AbstractAppender ("org.apache.daffodil.tdml", ThresholdFilter.createFilter(Level.INFO, Result.ACCEPT, Result.DENY), null, false, null) {
+
+ import TDMLAppender._
+
+ override def append(event: LogEvent): Unit = {
+ diagnostics = new LogDiagnostic(event.getMessage.getFormattedMessage) +: diagnostics
+ }
+}
+
+object TDMLAppender{
+ var diagnostics: Seq[Diagnostic] = Nil
+ var diagnostics2: Seq[String] = Nil
Review comment:
These var's in a object doesn't feel thread safe? Could there be issues if multiple TDML tests are run in parrallel?
##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
##########
@@ -599,8 +606,17 @@ abstract class TestCase(testCaseXML: NodeSeq, val parent: DFDLTestSuite) {
lazy val optExpectedOrInputInfoset = (testCaseXML \ "infoset").headOption.map { node => new Infoset(node, this) }
lazy val optExpectedErrors: Option[ExpectedErrors] = (testCaseXML \ "errors").headOption.map { node => ExpectedErrors(node, this) }
lazy val optExpectedWarnings: Option[ExpectedWarnings] = (testCaseXML \ "warnings").headOption.map { node => ExpectedWarnings(node, this) }
+ lazy val optExpectedLogs: Option[ExpectedLogs] = (testCaseXML \ "logs").headOption.map { node => ExpectedLogs(node, this) }
lazy val optExpectedValidationErrors: Option[ExpectedValidationErrors] = (testCaseXML \ "validationErrors").headOption.map { node => ExpectedValidationErrors(node, this) }
+ if(LogManager.getRootLogger().asInstanceOf[log4jLogger].getAppenders().get("org.apache.tdml")==null && optExpectedLogs.isDefined){
+ val tdmlAppender = TDMLAppender.createAppender
+ val loggers = LogManager.getRootLogger().asInstanceOf[log4jLogger]
+ loggers.addAppender(tdmlAppender)
+ tdmlAppender.start()
+ Configurator.setLevel("org.apache.daffodil", Level.INFO)
+ }
Review comment:
Similar question as above, how does this deal with tests run in multiple thredas? I'm not sure exaclty what's happening here but it seems like it's changing the global logger, which could affect other tests?
##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
##########
@@ -1451,6 +1491,10 @@ case class UnparserTestCase(ptc: NodeSeq, parentArg: DFDLTestSuite)
if (!isCrossTest(implString.get) ||
parent.shouldDoWarningComparisonOnCrossTests)
VerifyTestCase.verifyAllDiagnosticsFound(actual.getDiagnostics, optWarnings, implString)
+
+ if (!isCrossTest(implString.get) ||
+ parent.shouldDoLogComparisonOnCrossTests)
Review comment:
Why are there all these missing codecov lines? Seems like we have tests that should hit them?
##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
##########
@@ -1149,6 +1183,7 @@ case class ParserTestCase(ptc: NodeSeq, parentArg: DFDLTestSuite)
dataToParse: InputStream,
lengthLimitInBits: Long,
warnings: Option[ExpectedWarnings],
+ loggers: Option[ExpectedLogs],
Review comment:
Should this be `logs` instead of `loggers`?
##########
File path: project/Dependencies.scala
##########
@@ -32,6 +32,7 @@ object Dependencies {
"com.typesafe" % "config" % "1.4.2",
"org.apache.logging.log4j" %% "log4j-api-scala" % "12.0",
"org.apache.logging.log4j" % "log4j-api" % "2.17.2",
+ "org.apache.logging.log4j" % "log4j-core" % "2.17.2",
"org.apache.logging.log4j" % "log4j-core" % "2.17.2" % "it,test",
Review comment:
log4j-core was intentionally not part of core. The assumption was that users that get Daffodil via maven can add whatever log4j implementation as a dependency that they want. This way we don't force a particular implementation.
With the tdml-runner now using code that depends on log4j-core, that may not be possible now. I'm not sure if there's away around this, but maybe it's not a big deal if log4j-core is now a hard dependency for Daffodil?
Note that if we remove line 36, we can also remove line 50 in the cli dependency (our CLI does bundle log4j-core).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org