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-sbt.git
The following commit(s) were added to refs/heads/main by this push:
new fa20f96 Display Daffodil logs in packageDaffodilBin task
fa20f96 is described below
commit fa20f961b859f3ad40d0419a491533f1d71af1b0
Author: Steve Lawrence <[email protected]>
AuthorDate: Fri Jan 3 08:35:02 2025 -0500
Display Daffodil logs in packageDaffodilBin task
We currently add slf4j-nop to the packageDaffodilBin classpath which
silently drops all log messages from Daffodil. Sometimes these log
messages could be very helpful.
To enable this, this replaces slf4j-nop with slf4j-simple which just
outputs to the console. This also defines a number of system properites
so that packageDaffodilBin/logLevel is used to control the log level
sl4fj and log4j loggers. This also make log messages go to stdout
instead of the default stderr, since SBT makes strderr messages look
like errors, when in reality these are just information messages about
schema compilation.
Fixes #75
---
README.md | 12 +++++++++++
.../scala/org/apache/daffodil/DaffodilPlugin.scala | 24 +++++++++++++++++++---
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index edf0d80..e4ca609 100644
--- a/README.md
+++ b/README.md
@@ -183,6 +183,18 @@ provide to the JVM used to save parsers. For example:
packageDaffodilBin / javaOptions ++= Seq("-Xmx8G", "-Xss4m")
```
+In some cases it may be useful to enable more verbose logging when building a
+saved parser. To configure the log level, add the following to build.sbt:
+
+```scala
+packageDaffodilBin / logLevel := Level.Info
+```
+
+The above setting defaults to `Level.Warn` but can be set to `Level.Info` or
+`Level.Debug` for more verbosity. Note that this does not affect Schema
+Definition Warning or Error diagnostics--it only affects the Daffodil logging
+mechanism, usually intended for Daffodil developers.
+
### Saved Parsers in TDML Tests
For schemas that take a long time to compile, it is often convenient to use a
diff --git a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
index ed84952..1727255 100644
--- a/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
+++ b/src/main/scala/org/apache/daffodil/DaffodilPlugin.scala
@@ -270,10 +270,9 @@ object DaffodilPlugin extends AutoPlugin {
daffodilPackageBinVersions.value.flatMap { binDaffodilVersion =>
val cfg = ivyConfigName(binDaffodilVersion)
val dafDep = "org.apache.daffodil" %% "daffodil-japi" %
binDaffodilVersion % cfg
- // logging backends used to hide warnings about missing backends,
Daffodil won't
- // actually output logs that we care about, so this doesn't really
matter
+ // Add logging backends used when packageDaffodilBin outputs log
messages
val logMappings = Map(
- ">=3.5.0" -> "org.slf4j" % "slf4j-nop" % "2.0.9" % cfg,
+ ">=3.5.0" -> "org.slf4j" % "slf4j-simple" % "2.0.9" % cfg,
"<3.5.0" -> "org.apache.logging.log4j" % "log4j-core" % "2.20.0" %
cfg
)
val logDep = filterVersions(binDaffodilVersion, logMappings).head
@@ -406,6 +405,25 @@ object DaffodilPlugin extends AutoPlugin {
val savedParsers = cachedFun(filesToWatch)
savedParsers.toSeq
},
+
+ /**
+ * SBT ignores the packageDaffodilBin / logLevel setting, so we use it as
the logLevel to
+ * provide to daffodil when saving a parser. We default to warn because
Daffodils "info" is
+ * usually too verbose
+ */
+ packageDaffodilBin / logLevel := Level.Warn,
+
+ /**
+ * JVM options used for the forked process to build saved parsers
+ *
+ * Defaults to just setting various system properties to configure loggers
that might be
+ * used by different daffodil versions
+ */
+ packageDaffodilBin / javaOptions := Seq(
+ s"-Dorg.slf4j.simpleLogger.logFile=System.out",
+ s"-Dorg.slf4j.simpleLogger.defaultLogLevel=${(packageDaffodilBin /
logLevel).value}",
+ s"-Dorg.apache.logging.log4j.level=${(packageDaffodilBin /
logLevel).value}"
+ ),
packageDaffodilBin := {
val logger = streams.value.log