aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/xyz/driver/core/logging
diff options
context:
space:
mode:
authorvlad <vlad@driver.xyz>2017-11-08 04:09:28 -0800
committervlad <vlad@driver.xyz>2017-11-08 04:09:28 -0800
commit56f7aa3b6a45d4309cc2c77fcac7e6fda5f45e55 (patch)
treeadcb1cd20ec844a575f088b29a17236e335273c7 /src/main/scala/xyz/driver/core/logging
parent101c451480649c6d4aa8efb0294adf439512f8be (diff)
downloaddriver-core-56f7aa3b6a45d4309cc2c77fcac7e6fda5f45e55.tar.gz
driver-core-56f7aa3b6a45d4309cc2c77fcac7e6fda5f45e55.tar.bz2
driver-core-56f7aa3b6a45d4309cc2c77fcac7e6fda5f45e55.zip
App initialization convenience methods
Diffstat (limited to 'src/main/scala/xyz/driver/core/logging')
-rw-r--r--src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala
index 9f8db3e..f39f31d 100644
--- a/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala
+++ b/src/main/scala/xyz/driver/core/logging/MdcExecutionContext.scala
@@ -13,17 +13,14 @@ import scala.concurrent.ExecutionContext
class MdcExecutionContext(executionContext: ExecutionContext) extends ExecutionContext {
override def execute(runnable: Runnable): Unit = {
val callerMdc = MDC.getCopyOfContextMap
- executionContext.execute(new Runnable {
- def run(): Unit = {
- // copy caller thread diagnostic context to execution thread
- // scalastyle:off
- if (callerMdc != null) MDC.setContextMap(callerMdc)
- try {
- runnable.run()
- } finally {
- // the thread might be reused, so we clean up for the next use
- MDC.clear()
- }
+ executionContext.execute(() => {
+ // copy caller thread diagnostic context to execution thread
+ Option(callerMdc).foreach(MDC.setContextMap)
+ try {
+ runnable.run()
+ } finally {
+ // the thread might be reused, so we clean up for the next use
+ MDC.clear()
}
})
}