Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion mdc-logback/src/main/scala/ox/logback/InheritableMDC.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Loading