Skip to content

Instantly share code, notes, and snippets.

@lforite
Created December 10, 2019 14:39
Show Gist options
  • Select an option

  • Save lforite/159cf5631e750037471ac0a53d5c360a to your computer and use it in GitHub Desktop.

Select an option

Save lforite/159cf5631e750037471ac0a53d5c360a to your computer and use it in GitHub Desktop.
And example of thread MDCs usage
//storing a correlation id in thread local variables
MDC.put("correlationId", Random.alphanumeric.take(8).mkString)
//retrieving the correlation id
val correlationId = MDC.get("correlationId")
trait Logger {
def error(msg: String, t: Throwable): Unit
def info(msg: String): Unit = {
underlyingLogger.info(s"[${MDC.get("correlationId")}] $msg")
}
def debug(msg: String): Unit
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment