https://kotlinlang.org logo
#ktor
Title
# ktor
a

Anders Sveen

02/16/2021, 10:22 AM
How can I get logging dispatched from the response in KTor Client to respect the MDC entries I get in all other log entries? I have been digging around for hours, but almost losing my mind... 🙂 I have looked for ways to set the coroutineContext for the HttpClitent etc. but I am getting lost in code. 😉 Any pointers or solutions is much appreciated. 🙂
👀 1
Never mind. After failing and failing I finally stumbled upon a combination that works.
Copy code
withContext(ktorClient.coroutineContext + MDCContext()) { ... }
🥳🦜🎉
(MDCContext is in the coroutine-slf4j library)
o

okarm

02/16/2021, 8:07 PM
Would you be willing to write a StackOverflow question with your own answer? You could save a lot of people a lot of time.
a

Anders Sveen

02/17/2021, 2:47 PM
Yep, I can do that. Just wrapping up some related stuff that can go into the solution. 🙂
Hey @okarm, what would be the "correct" way to do this? 🙂 Just create a question with a ktor tag and then answer it myself directly after? 🙂
5 Views