Skip to content

Commit

Permalink
Only log the context, not the MDC contents
Browse files Browse the repository at this point in the history
  • Loading branch information
morgen-peschke committed Jun 25, 2024
1 parent 2d5bc1c commit 31abf17
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import cats.effect._
import org.slf4j.{Logger => JLogger}
import org.slf4j.MDC

import java.util

private[slf4j] object Slf4jLoggerInternal {

final val singletonsByName = true
Expand Down Expand Up @@ -49,8 +51,12 @@ private[slf4j] object Slf4jLoggerInternal {
new util.HashMap[String, String]()
}

try logging()
finally
try {
// Once 2.12 is no longer supported, change this to MDC.setContextMap(ctx.asJava)
MDC.clear()
ctx.foreach { case (k, v) => MDC.put(k, v) }
logging()
} finally
if (backup eq null) MDC.clear()
else MDC.setContextMap(backup)
}
Expand Down

0 comments on commit 31abf17

Please sign in to comment.