Created
December 10, 2019 14:39
-
-
Save lforite/159cf5631e750037471ac0a53d5c360a to your computer and use it in GitHub Desktop.
And example of thread MDCs usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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