From 9d219f756ad32760a9a2e0f65e64bb71eaf06755 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Tue, 4 Jun 2024 17:07:50 +0200 Subject: [PATCH 1/3] Fix dependencies to be platformed and fix newly enabled tests --- build.sbt | 96 ++++++++----------- .../src/test/scala/specs/LoggingSpec.scala | 26 ++--- .../AsynchronousLoggingSpec.scala | 2 +- .../src/test/scala/specs/MDCThreadSpec.scala | 47 +++++++++ .../shared/src/test/scala/specs/MDCSpec.scala | 32 ------- .../src/test/scala/spec/FileLoggingSpec.scala | 0 .../src/test/scala/spec/JsonWriterSpec.scala | 0 7 files changed, 104 insertions(+), 99 deletions(-) rename core/{shared => js-jvm}/src/test/scala/specs/LoggingSpec.scala (94%) rename core/jvm/src/test/scala/{spec => specs}/AsynchronousLoggingSpec.scala (99%) create mode 100644 core/jvm/src/test/scala/specs/MDCThreadSpec.scala rename fileModule/{shared => jvm}/src/test/scala/spec/FileLoggingSpec.scala (100%) rename jsonFabric/{shared => jvm}/src/test/scala/spec/JsonWriterSpec.scala (100%) diff --git a/build.sbt b/build.sbt index 2df936e11..4a3dbb0f1 100644 --- a/build.sbt +++ b/build.sbt @@ -100,11 +100,11 @@ val sourceMapSettings = List( lazy val root = project.in(file(".")) .aggregate( - coreJS, coreJVM, coreNative, - // TODO: Re-enable catsNative when cats-effect supports ScalaNative 0.5 - catsJS, catsJVM, //catsNative, - fileJVM, fileNative, - jsonJS, jsonJVM, jsonFabricJS, jsonFabricJVM, jsonCirceJS, jsonCirceJVM, + core.js, core.jvm, core.native, + // TODO: Re-enable cats.native when cats-effect supports ScalaNative 0.5 + cats.js, cats.jvm, //cats.native, + fileModule.jvm, fileModule.native, + json.js, json.jvm, jsonFabric.js, jsonFabric.jvm, jsonCirce.js, jsonCirce.jvm, slf4j, slf4j2, log4j, migration, config, slack, logstash ) .settings( @@ -120,7 +120,7 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) libraryDependencies ++= Seq( "com.outr" %%% "perfolation" % perfolationVersion, "com.lihaoyi" %%% "sourcecode" % sourcecodeVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), libraryDependencies ++= ( if (scalaVersion.value.startsWith("2.12.")) { @@ -134,13 +134,15 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) ) .jvmSettings( libraryDependencies ++= Seq( - "com.outr" %% "moduload" % moduloadVersion + "com.outr" %%% "moduload" % moduloadVersion + ) + ) + .jsSettings( + libraryDependencies ++= Seq( + "io.github.cquiroz" %%% "scala-java-time" % "2.5.0" % Test, + "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.5.0" % Test ) ) - -lazy val coreJS = core.js -lazy val coreJVM = core.jvm -lazy val coreNative = core.native lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform) .crossType(CrossType.Full) @@ -149,8 +151,8 @@ lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform) crossScalaVersions := allScalaVersions, libraryDependencies ++= Seq( "org.typelevel" %%% "cats-effect" % catsEffectVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test, - "org.typelevel" %% "cats-effect-testing-scalatest" % catsEffectTestingVersion % "test" + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test, + "org.typelevel" %%% "cats-effect-testing-scalatest" % catsEffectTestingVersion % "test" ), libraryDependencies ++= ( if (scalaVersion.value.startsWith("2.12.")) { @@ -163,16 +165,12 @@ lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform) ) .dependsOn(core) -lazy val catsJS = cats.js -lazy val catsJVM = cats.jvm -//lazy val catsNative = cats.native - lazy val fileModule = crossProject(JVMPlatform, NativePlatform) .crossType(CrossType.Full) .settings( name := "scribe-file", libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) @@ -184,99 +182,87 @@ lazy val fileModule = crossProject(JVMPlatform, NativePlatform) ) .dependsOn(core) -lazy val fileJVM = fileModule.jvm -lazy val fileNative = fileModule.native - lazy val json = crossProject(JSPlatform, JVMPlatform) .crossType(CrossType.Full) .settings( name := "scribe-json", libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) .dependsOn(core) -lazy val jsonJS = json.js -lazy val jsonJVM = json.jvm - lazy val jsonFabric = crossProject(JSPlatform, JVMPlatform) .crossType(CrossType.Full) .settings( name := "scribe-json-fabric", libraryDependencies ++= Seq( "org.typelevel" %%% "fabric-io" % fabricVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) .dependsOn(json) -lazy val jsonFabricJS = jsonFabric.js -lazy val jsonFabricJVM = jsonFabric.jvm - lazy val jsonCirce = crossProject(JSPlatform, JVMPlatform) .crossType(CrossType.Full) .settings( name := "scribe-json-circe", libraryDependencies ++= Seq( - "io.circe" %% "circe-core" % circeVersion, - "io.circe" %% "circe-parser" % circeVersion, - "io.circe" %% "circe-generic" % circeVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "io.circe" %%% "circe-core" % circeVersion, + "io.circe" %%% "circe-parser" % circeVersion, + "io.circe" %%% "circe-generic" % circeVersion, + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) .dependsOn(json) -lazy val jsonCirceJS = jsonCirce.js -lazy val jsonCirceJVM = jsonCirce.jvm - lazy val slf4j = project.in(file("slf4j")) - .dependsOn(coreJVM) + .dependsOn(core.jvm) .settings( name := "scribe-slf4j", Test / publishArtifact := false, libraryDependencies ++= Seq( "org.slf4j" % "slf4j-api" % slf4jVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) lazy val slf4j2 = project.in(file("slf4j2")) - .dependsOn(coreJVM) + .dependsOn(core.jvm) .settings( name := "scribe-slf4j2", Test / publishArtifact := false, libraryDependencies ++= Seq( "org.slf4j" % "slf4j-api" % slf4j2Version, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) lazy val log4j = project.in(file("log4j")) - .dependsOn(coreJVM) + .dependsOn(core.jvm) .settings( name := "scribe-log4j", Test / publishArtifact := false, libraryDependencies ++= Seq( "org.apache.logging.log4j" % "log4j-api" % log4jVersion, "org.apache.logging.log4j" % "log4j-core" % log4jVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) lazy val migration = project.in(file("migration")) - .dependsOn(coreJVM) + .dependsOn(core.jvm) .settings( name := "scribe-migration", Test / publishArtifact := false, libraryDependencies ++= Seq( - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) @@ -287,8 +273,8 @@ lazy val config = project.in(file("config")) name := "scribe-config", Test / publishArtifact := false, libraryDependencies ++= Seq( - "com.outr" %% "profig" % profigVersion, - "org.scalatest" %% "scalatest" % scalaTestVersion % Test + "com.outr" %%% "profig" % profigVersion, + "org.scalatest" %%% "scalatest" % scalaTestVersion % Test ), crossScalaVersions := allScalaVersions ) @@ -298,23 +284,23 @@ lazy val slack = project.in(file("slack")) name := "scribe-slack", crossScalaVersions := List(scala213, scala3), libraryDependencies ++= Seq( - "com.outr" %% "spice-client-okhttp" % spiceVersion + "com.outr" %%% "spice-client-okhttp" % spiceVersion ) ) - .dependsOn(coreJVM) + .dependsOn(core.jvm) lazy val logstash = project.in(file("logstash")) .settings( name := "scribe-logstash", crossScalaVersions := List(scala213, scala3), libraryDependencies ++= Seq( - "com.outr" %% "spice-client-okhttp" % spiceVersion + "com.outr" %%% "spice-client-okhttp" % spiceVersion ) ) - .dependsOn(coreJVM) + .dependsOn(core.jvm) lazy val benchmarks = project.in(file("benchmarks")) - .dependsOn(fileJVM, catsJVM) + .dependsOn(fileModule.jvm, cats.jvm) .enablePlugins(JmhPlugin) .settings( fork := true, @@ -325,11 +311,11 @@ lazy val benchmarks = project.in(file("benchmarks")) "com.lmax" % "disruptor" % disruptorVersion, "ch.qos.logback" % "logback-classic" % logbackVersion, "com.typesafe" % "config" % typesafeConfigVersion, - "com.typesafe.scala-logging" %% "scala-logging" % scalaLoggingVersion, + "com.typesafe.scala-logging" %%% "scala-logging" % scalaLoggingVersion, "org.tinylog" % "tinylog" % tinyLogVersion, - "org.log4s" %% "log4s" % log4sVersion, - "org.typelevel" %% "log4cats-slf4j" % log4catsVersion, - "co.fs2" %% "fs2-core" % fs2Version + "org.log4s" %%% "log4s" % log4sVersion, + "org.typelevel" %%% "log4cats-slf4j" % log4catsVersion, + "co.fs2" %%% "fs2-core" % fs2Version ) ) diff --git a/core/shared/src/test/scala/specs/LoggingSpec.scala b/core/js-jvm/src/test/scala/specs/LoggingSpec.scala similarity index 94% rename from core/shared/src/test/scala/specs/LoggingSpec.scala rename to core/js-jvm/src/test/scala/specs/LoggingSpec.scala index f3bb8c476..5ac7d211e 100644 --- a/core/shared/src/test/scala/specs/LoggingSpec.scala +++ b/core/js-jvm/src/test/scala/specs/LoggingSpec.scala @@ -457,18 +457,22 @@ class LoggingSpec extends AnyWordSpec with Matchers with Logging { writer.output.map(_.plainText) should be(List("error")) } "use HTMLOutputFormat to log something" in { - val MomentInTime = 1606235160799L - Time.contextualize(MomentInTime) { - val b = new StringBuilder - val writer = new Writer { - override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = { - outputFormat(output, b.append(_)) + sys.props("java.vm.name") match { + case "Scala.js" | "Scala Native" => + case _ => + val MomentInTime = 1606235160799L + Time.contextualize(MomentInTime) { + val b = new StringBuilder + val writer = new Writer { + override def write(record: LogRecord, output: LogOutput, outputFormat: OutputFormat): Unit = { + outputFormat(output, b.append(_)) + } + } + val logger = Logger().orphan().withHandler(writer = writer, outputFormat = HTMLOutputFormat()) + Thread.currentThread().setName("test-thread") + logger.info("Hello, HTML!") + b.toString() should be("""
2020.11.24 10:26:00:799 test-thread INFO specs.LoggingSpec.LoggingSpec:473
    Hello, HTML!    
""") } - } - val logger = Logger().orphan().withHandler(writer = writer, outputFormat = HTMLOutputFormat()) - Thread.currentThread().setName("test-thread") - logger.info("Hello, HTML!") - b.toString() should be("""
2020.11.24 10:26:00:799 test-thread INFO specs.LoggingSpec.LoggingSpec:470
    Hello, HTML!    
""") } } } diff --git a/core/jvm/src/test/scala/spec/AsynchronousLoggingSpec.scala b/core/jvm/src/test/scala/specs/AsynchronousLoggingSpec.scala similarity index 99% rename from core/jvm/src/test/scala/spec/AsynchronousLoggingSpec.scala rename to core/jvm/src/test/scala/specs/AsynchronousLoggingSpec.scala index 509bb5f75..5e989c861 100644 --- a/core/jvm/src/test/scala/spec/AsynchronousLoggingSpec.scala +++ b/core/jvm/src/test/scala/specs/AsynchronousLoggingSpec.scala @@ -1,4 +1,4 @@ -package spec +package specs import org.scalatest.matchers.should.Matchers import org.scalatest.wordspec.AnyWordSpec diff --git a/core/jvm/src/test/scala/specs/MDCThreadSpec.scala b/core/jvm/src/test/scala/specs/MDCThreadSpec.scala new file mode 100644 index 000000000..b00cfc647 --- /dev/null +++ b/core/jvm/src/test/scala/specs/MDCThreadSpec.scala @@ -0,0 +1,47 @@ +package specs + +import org.scalatest.matchers.should.Matchers +import org.scalatest.wordspec.AnyWordSpec +import scribe.Logger +import scribe.mdc._ +import scribe.writer.CacheWriter + +class MDCThreadSpec extends AnyWordSpec with Matchers { + private lazy val writer = new CacheWriter + private lazy val logger = Logger("mdc-test").orphan().withHandler(writer = writer) + + "MDC" should { + "verify concurrency access to implicits" in { + implicit val mdc: MDC = MDC.instance + logger.info("Zero") + mdc.context("test" -> "testing") { + logger.info("One") + mdc.context("test" -> "testing2") { + logger.info("Two") + var finished = false + new Thread { + override def run(): Unit = { + logger.info("Three") + finished = true + } + }.start() + while (!finished) { + Thread.sleep(10) + } + } + logger.info("Four") + } + logger.info("Five") + writer.consume { list => + list.map(r => r.messages.head.logOutput.plainText -> r.data.get("test").map(_())) should be(List( + "Five" -> None, + "Four" -> Some("testing"), + "Three" -> Some("testing2"), + "Two" -> Some("testing2"), + "One" -> Some("testing"), + "Zero" -> None + )) + } + } + } +} diff --git a/core/shared/src/test/scala/specs/MDCSpec.scala b/core/shared/src/test/scala/specs/MDCSpec.scala index 21e7ec881..ce97d90e5 100644 --- a/core/shared/src/test/scala/specs/MDCSpec.scala +++ b/core/shared/src/test/scala/specs/MDCSpec.scala @@ -37,37 +37,5 @@ class MDCSpec extends AnyWordSpec with Matchers { )) } } - "verify concurrency access to implicits" in { - implicit val mdc: MDC = MDC.instance - logger.info("Zero") - mdc.context("test" -> "testing") { - logger.info("One") - mdc.context("test" -> "testing2") { - logger.info("Two") - var finished = false - new Thread { - override def run(): Unit = { - logger.info("Three") - finished = true - } - }.start() - while (!finished) { - Thread.sleep(10) - } - } - logger.info("Four") - } - logger.info("Five") - writer.consume { list => - list.map(r => r.messages.head.logOutput.plainText -> r.data.get("test").map(_())) should be(List( - "Five" -> None, - "Four" -> Some("testing"), - "Three" -> Some("testing2"), - "Two" -> Some("testing2"), - "One" -> Some("testing"), - "Zero" -> None - )) - } - } } } diff --git a/fileModule/shared/src/test/scala/spec/FileLoggingSpec.scala b/fileModule/jvm/src/test/scala/spec/FileLoggingSpec.scala similarity index 100% rename from fileModule/shared/src/test/scala/spec/FileLoggingSpec.scala rename to fileModule/jvm/src/test/scala/spec/FileLoggingSpec.scala diff --git a/jsonFabric/shared/src/test/scala/spec/JsonWriterSpec.scala b/jsonFabric/jvm/src/test/scala/spec/JsonWriterSpec.scala similarity index 100% rename from jsonFabric/shared/src/test/scala/spec/JsonWriterSpec.scala rename to jsonFabric/jvm/src/test/scala/spec/JsonWriterSpec.scala From c0a4516b99bf114f5dba74c9f1b8350daca2b17b Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Tue, 4 Jun 2024 17:50:20 +0200 Subject: [PATCH 2/3] . --- build.sbt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4a3dbb0f1..58e724c26 100644 --- a/build.sbt +++ b/build.sbt @@ -143,6 +143,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform) "io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.5.0" % Test ) ) + .nativeSettings( + coverageEnabled := false + ) lazy val cats = crossProject(JVMPlatform, JSPlatform) //, NativePlatform) .crossType(CrossType.Full) @@ -284,7 +287,7 @@ lazy val slack = project.in(file("slack")) name := "scribe-slack", crossScalaVersions := List(scala213, scala3), libraryDependencies ++= Seq( - "com.outr" %%% "spice-client-okhttp" % spiceVersion + "com.outr" %% "spice-client-okhttp" % spiceVersion ) ) .dependsOn(core.jvm) @@ -294,7 +297,7 @@ lazy val logstash = project.in(file("logstash")) name := "scribe-logstash", crossScalaVersions := List(scala213, scala3), libraryDependencies ++= Seq( - "com.outr" %%% "spice-client-okhttp" % spiceVersion + "com.outr" %% "spice-client-okhttp" % spiceVersion ) ) .dependsOn(core.jvm) From cd5d6897f8ae9602fc703648e4907066dc75b1df Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Tue, 4 Jun 2024 19:47:51 +0200 Subject: [PATCH 3/3] Update spice to `0.5.9` --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 58e724c26..fbcc6b496 100644 --- a/build.sbt +++ b/build.sbt @@ -67,7 +67,7 @@ val slf4j2Version: String = "2.0.13" val profigVersion: String = "3.4.1" // Slack and Logstash Dependencies -val spiceVersion: String = "0.5.7" +val spiceVersion: String = "0.5.9" // Benchmarking Dependencies val log4jVersion: String = "2.23.1"