From 2f7f929d99fa26c1dc6a600c75fe8c0480869761 Mon Sep 17 00:00:00 2001 From: scala-steward Date: Thu, 27 Feb 2025 00:18:41 +0000 Subject: [PATCH 1/2] Update logback-classic to 1.5.17 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a6af7ed4..813b1b2a 100644 --- a/build.sbt +++ b/build.sbt @@ -18,7 +18,7 @@ lazy val commonSettings = commonSmlBuildSettings ++ ossPublishSettings ++ Seq( val scalaTest = "org.scalatest" %% "scalatest" % "3.2.19" % Test val slf4j = "org.slf4j" % "slf4j-api" % "2.0.17" -val logback = "ch.qos.logback" % "logback-classic" % "1.5.16" +val logback = "ch.qos.logback" % "logback-classic" % "1.5.17" // used during CI to verify that the documentation compiles val compileDocumentation: TaskKey[Unit] = taskKey[Unit]("Compiles documentation throwing away its output") From e19a46b1f2e944d0f31cfc31f5606e83c91c98b5 Mon Sep 17 00:00:00 2001 From: adamw Date: Wed, 12 Mar 2025 13:15:10 +0100 Subject: [PATCH 2/2] Fix MDC scoped value adapter --- .../src/main/scala/ox/logback/InheritableMDC.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mdc-logback/src/main/scala/ox/logback/InheritableMDC.scala b/mdc-logback/src/main/scala/ox/logback/InheritableMDC.scala index dc2d1bd5..0c7056eb 100644 --- a/mdc-logback/src/main/scala/ox/logback/InheritableMDC.scala +++ b/mdc-logback/src/main/scala/ox/logback/InheritableMDC.scala @@ -21,7 +21,7 @@ object InheritableMDC: private val logger: Logger = LoggerFactory.getLogger(getClass.getName) private[logback] val currentContext: ForkLocal[Option[MDCAdapter]] = ForkLocal(None) - /** Initialise inheritable MDCs. Must be called as early in the app's code as possible. */ + /** Initialize inheritable MDCs. Must be called as early in the app's code as possible. */ lazy val init: Unit = // Obtaining the current provider, to replace it later with our implementation returning the correct MDCAdapter. val getProviderMethod = classOf[LoggerFactory].getDeclaredMethod("getProvider") @@ -41,6 +41,12 @@ object InheritableMDC: providerField.setAccessible(true) providerField.set(null, new OverrideMDCAdapterDelegateProvider(currentProvider, scopedValuedMDCAdapter)) + // in Logback 1.5.17+ the MDC class is initialized earlier, which means that the MDC adapter is stored earlier + // hence, overwriting it here as well + val mdcStaticField = classOf[MDC].getDeclaredField("MDC_ADAPTER") + mdcStaticField.setAccessible(true) + mdcStaticField.set(null, scopedValuedMDCAdapter) + logger.info(s"Scoped-value based MDC initialized") case currentProvider => logger.warn(s"A non-Logback SLF4J provider ($currentProvider) is being used, unable to initialize scoped-value based MDC")