tuxji commented on code in PR #954:
URL: https://github.com/apache/daffodil/pull/954#discussion_r1100685961


##########
build.sbt:
##########
@@ -36,7 +36,28 @@ lazy val genExamples = taskKey[Seq[File]]("Generate runtime2 
example files")
 
 lazy val daffodil         = project.in(file(".")).configs(IntegrationTest)
                               .enablePlugins(JavaUnidocPlugin, 
ScalaUnidocPlugin)
-                              .aggregate(macroLib, propgen, lib, io, runtime1, 
runtime1Unparser, runtime1Layers, runtime2, core, japi, sapi, tdmlLib, 
tdmlProc, cli, udf, schematron, test, testIBM1, tutorials, testStdLayout)
+                              .aggregate(
+                                 macroLib,
+                                 propgen,
+                                 slf4jLogger,
+                                 lib,
+                                 io,
+                                 runtime1,
+                                 runtime1Unparser,
+                                 runtime1Layers,
+                                 runtime2,
+                                 core,
+                                 japi,
+                                 sapi,
+                                 tdmlLib,
+                                 tdmlProc,
+                                 cli,
+                                 udf,
+                                 schematron,
+                                 test,
+                                 testIBM1,
+                                 tutorials,
+                                 testStdLayout)

Review Comment:
   Does the order matter, or can the lines be sorted alphabetically?



##########
project/Dependencies.scala:
##########
@@ -30,9 +30,11 @@ object Dependencies {
     "xml-resolver" % "xml-resolver" % "1.2",
     "commons-io" % "commons-io" % "2.11.0",
     "com.typesafe" % "config" % "1.4.2",
-    "org.apache.logging.log4j" %% "log4j-api-scala" % "12.0",
-    "org.apache.logging.log4j" % "log4j-api" % "2.19.0",
-    "org.apache.logging.log4j" % "log4j-core" % "2.19.0" % "it,test",
+    "com.typesafe.scala-logging" %% "scala-logging" % "3.9.4",

Review Comment:
   Is Daffodil really using anything from the scala-logging library?  The calls 
I see seem to be going directly to the underlying SLF4J Java classes.
   
   Actually, we do use scalalogging.Logger as the type of logger.log, so we're 
indeed using that library whenever code calls logger.log.info(...).



##########
daffodil-cli/src/conf/.keep:
##########
@@ -0,0 +1,14 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more

Review Comment:
   Why do we want to keep the `daffodil-cli/src/conf` directory around if we 
don't need a logging configuration file anymore?  Is the conf directory used as 
a placeholder for other configuration files that Daffodil will read if it finds 
them in that directory (within the built product)?



##########
build.sbt:
##########
@@ -47,30 +68,34 @@ lazy val macroLib         = Project("daffodil-macro-lib", 
file("daffodil-macro-l
 lazy val propgen          = Project("daffodil-propgen", 
file("daffodil-propgen")).configs(IntegrationTest)
                               .settings(commonSettings, nopublish)
 
+lazy val slf4jLogger      = Project("daffodil-slf4j-logger", 
file("daffodil-slf4j-logger")).configs(IntegrationTest)
+                              .settings(commonSettings)
+                              .settings(libraryDependencies ++= 
Dependencies.slf4jAPI)
+

Review Comment:
   What are the benefits of putting slf4jLogger in its own module as opposed to 
core or lib?  Easier compilation?  More fine-grained dependency management?



##########
daffodil-slf4j-logger/src/main/scala/org/apahe/daffodil/slf4j/DaffodilSLF4JLogger.scala:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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.slf4j
+
+import java.io.PrintStream
+import java.util.concurrent.ConcurrentHashMap
+
+import org.slf4j.ILoggerFactory
+import org.slf4j.IMarkerFactory
+import org.slf4j.Logger
+import org.slf4j.Marker
+import org.slf4j.event.Level
+import org.slf4j.helpers.BasicMarkerFactory
+import org.slf4j.helpers.LegacyAbstractLogger
+import org.slf4j.helpers.MessageFormatter
+import org.slf4j.helpers.NOPMDCAdapter
+import org.slf4j.spi.MDCAdapter
+import org.slf4j.spi.SLF4JServiceProvider
+
+class DaffodilSLF4JServiceProvider extends SLF4JServiceProvider {
+  override lazy val getLoggerFactory: ILoggerFactory = new 
DaffodilLoggerFactory()
+  override lazy val getMarkerFactory: IMarkerFactory = new BasicMarkerFactory()
+  override lazy val getMDCAdapter: MDCAdapter = new NOPMDCAdapter()
+  override lazy val getRequestedApiVersion: String = "2.0.99"
+  override def initialize(): Unit = {}
+}
+
+class DaffodilLoggerFactory extends ILoggerFactory {
+
+  private val loggerMap = new ConcurrentHashMap[String, DaffodilLogger]()
+
+  override def getLogger(name: String): Logger = {
+    val daffodilLogger = loggerMap.get(name)
+    if (daffodilLogger != null) {
+      daffodilLogger
+    } else {
+      val newInstance = new DaffodilLogger(name)
+      val oldInstance = loggerMap.putIfAbsent(name, newInstance)
+      if (oldInstance == null) {
+        newInstance
+      } else {
+        oldInstance
+      }
+    }
+  }
+}
+
+/**
+ * A logger that should only be used by specifically by Daffodil (e.g. CLI, 
TDML
+ * Runner) to support thread specific log levels and log streams. This is 
mostly
+ * useful for testing where we want to allow each test thread to log at a
+ * different level and stream. To set the level and stream, one should call:
+ *
+ *   daffodilLogger.setThreadLoggerConfig(level, stream)
+ *
+ * When done, the config should be removed by calling:
+ *
+ *   daffodilLogger.removeThreadLoggerConfig()
+ */
+class DaffodilLogger(name: String) extends LegacyAbstractLogger {

Review Comment:
   Should we be concerned about the "Legacy" word in "LegacyAbstractLogger"?  I 
took a quick look at other Logger subclasses provided by slf4j and noticed that 
slf4j provides 
[SubstituteLogger](https://www.slf4j.org/api/org/slf4j/helpers/SubstituteLogger.html)
 which allows you to set a delete logger (the setDelete(logger) method) and 
logs to NOPLogger otherwise.  However, I'm not sure using `SubstituteLogger` 
would simplify this code.  We still would need a Logger implementation for 
writing to a PrintStream and 
[SimpleLogger](https://www.slf4j.org/api/org/slf4j/simple/SimpleLogger.html) 
doesn't seem to take a PrintStream as a constructor argument.  What you have in 
this class looks simple enough anyway.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to