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/03/31 04:31:23 UTC

[GitHub] [daffodil] alexanderrevello opened a new pull request #781: Daffodil 2643 tdml logs

alexanderrevello opened a new pull request #781:
URL: https://github.com/apache/daffodil/pull/781


   TDML unit tests can now capture and look for logs
   Like they do for warnings and errors, logs completed through log4j are
   captured and can be required in the tdml test cases. The root logger
   level is by default warning and when a tdml test is run, that level is
   changed to info in order to capture logs. Tests were added to
   demonstrate the feature as well as how it works in conjunction with
   warnings and errors. Library dependencies were updated to give tdml-lib
   access to log4jcore libraries needed to make an abstractappender
   
   DAFFODIL-2643


-- 
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



[GitHub] [daffodil] tuxji commented on pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
tuxji commented on pull request #781:
URL: https://github.com/apache/daffodil/pull/781#issuecomment-1084823349


   After your next commit, wait for the CI tests to finish so we can check whether the single windows error was a fluke or not:
   
   ```
   [error] Test org.apache.daffodil.tdml.TestTDMLRunnerLogs.test_unparserLogWhenExpectingError failed: org.apache.daffodil.tdml.TDMLExceptionImpl: (Implementation: daffodil) "Diagnostic message(s) were expected but not found."
   [error] Expected: dfdlx:trace
   [error]  No diagnostic messages were issued., took 0.65 sec
   ```
   
   It will be good to run the CI tests two more times (after your next commit, and then again after your squashed commit).


-- 
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



[GitHub] [daffodil] tuxji commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
tuxji commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r839787859



##########
File path: build.sbt
##########
@@ -104,6 +104,7 @@ lazy val sapi             = Project("daffodil-sapi", file("daffodil-sapi")).conf
 lazy val tdmlLib             = Project("daffodil-tdml-lib", file("daffodil-tdml-lib")).configs(IntegrationTest)
                               .dependsOn(macroLib % "compile-internal", lib, io, io % "test->test")
                               .settings(commonSettings)
+                              .settings(libraryDependencies ++= Dependencies.core)

Review comment:
       Why is this change even needed?  You have `.settings(commonSettings)` on the previous line and that calls libraryDependencies ++= Dependencies.common, in short, core ++ infoset ++ test.  

##########
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(

Review comment:
       Please add comments here and below explaining what each class and object is used for.

##########
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
+
+    @PluginFactory
+    def createAppender(): TDMLAppender = {
+            new TDMLAppender
+    }
+
+    def getDiagnostics(): Seq[Throwable] = {
+        diagnostics
+    }
+
+    def clearDiagnostics(): Unit = {
+        diagnostics = Nil
+    }
+}
+
+class LogDiagnostic(msg: String)

Review comment:
       I can't find where LogDiagnostic is used?

##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/RunnerFactory.scala
##########
@@ -91,6 +91,8 @@ object Runner {
    */
   def defaultShouldDoWarningComparisonOnCrossTests = false
 
+  def defaultShouldDoLogComparisonCrossTests = false

Review comment:
       Please add `On` for consistency, `defaultShouldDoLogComparisonOnCrossTests`.

##########
File path: daffodil-tdml-lib/src/main/scala/org/apache/daffodil/tdml/TDMLRunner.scala
##########
@@ -76,7 +76,10 @@ import org.apache.daffodil.util.Misc.hex2Bits
 import org.apache.daffodil.util.SchemaUtils
 import org.apache.daffodil.xml.DaffodilXMLLoader
 import org.apache.daffodil.xml.XMLUtils
-
+import org.apache.logging.log4j.LogManager
+import org.apache.logging.log4j.core.{Logger => log4jLogger}

Review comment:
       We capitalize classes by convention, `Log4jLogger`.

##########
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:
       I believe line 36 is extraneous now that you've added line 35.  If log4j-core is available in compile scope, it'll also be available in test and integration test scopes too.




-- 
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



[GitHub] [daffodil] stevedlawrence commented on pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
stevedlawrence commented on pull request #781:
URL: https://github.com/apache/daffodil/pull/781#issuecomment-1086251746


   > The TDML runner needs log4j core, so the CLI will because it can run TDML tests. But Daffodil proper, used via API as it would be when embedded into a system, should not need this logger specified. That tradeoff feels ok to me.
   
   Good point. So it seems in that case the new log4j-core API should not be part of the core dependencies, but instead should be added only to the tdmlLib project, similar to how we add it to the CLI? So something like:
   
   *Dependencies.scala*
   ```scala
   class Dependencies {
     ....
   
     lazy val tdml = Seq(
       "org.apache.logging.log4j" % "log4j-core" % "2.17.2"
     )
   }
   ```
   
   *build.sbt*
   ```scala
   lazy val tdmlLib = Project(...)
                      ...
                      .settings(libraryDependencies ++= Dependencies.tdml)
   ```


-- 
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



[GitHub] [daffodil] mbeckerle commented on pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
mbeckerle commented on pull request #781:
URL: https://github.com/apache/daffodil/pull/781#issuecomment-1086238308


   The TDML runner needs log4j core, so the CLI will because it can run TDML tests. But Daffodil proper, used via API as it would be when embedded into a system, should not need this logger specified.  That tradeoff feels ok to me. 


-- 
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



[GitHub] [daffodil] stevedlawrence commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
stevedlawrence commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840867724



##########
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:
       I think we only need it for the new `TDMLAppender`, which is defined and used in `daffodil-tdml-lib`. So I think only lib needs this new log4j-core dependency.
   
   Though you raise a good point, I think daffodil-tdml-procesor should be the thing aggregating logs, since different DFDL implementations will have different mechanisms for capturing logs. Daffodil uses log4j, but IBM DFDL might use something completely different. Seems maybe the new TDMLAppender wants to be moved to daffodil-tdml-processor, and the `DaffodilTDMLDFDLProcessor` must return the logs as part of the Parse/Unparse result and the TDMLRunner can then compare against the expected results?
   




-- 
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



[GitHub] [daffodil] stevedlawrence commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
stevedlawrence commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840868194



##########
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:
       Note that adding log4j-core as a dependency to the daffodil-tdml-proessor has a good side effect: Our schema projects that depend on daffodil-tdml-processor for running tests will now transitively pull in log4j-core, and it should get rid of that warning about not having a logger available.




-- 
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



[GitHub] [daffodil] stevedlawrence commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
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



[GitHub] [daffodil] mbeckerle commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
mbeckerle commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840850195



##########
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:
       Much of the features for cross testing don't get exercised unless you run the IBM cross testing rig. 
   
   To test these without that we'd have to build a mock cross tester that actually just uses daffodil. 




-- 
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



[GitHub] [daffodil] stevedlawrence commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
stevedlawrence commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840859974



##########
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:
       Ah right, I missed that this is only cross testing related. Not worth it to create a mock cross tester. Resolving this conversation.




-- 
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



[GitHub] [daffodil] mbeckerle commented on a change in pull request #781: Daffodil 2643 tdml logs

Posted by GitBox <gi...@apache.org>.
mbeckerle commented on a change in pull request #781:
URL: https://github.com/apache/daffodil/pull/781#discussion_r840852119



##########
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:
       Do we need log4j-core for daffodil-core test, or only daffodil-tdml-lib or even maybe only daffodil-tdml-processor? 




-- 
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