-
-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: MDC support #31
Comments
looks like a neat idea! any other suggestions? |
How about an extension method instead: inline fun <T> Pair<String, String>.asLoggingContextOf(body: () -> T): T =
MDC.putCloseable(first, second).use { body() } |
That works well if you have a single key/value pair you want to put into context. I think that coming up with the right API here will be a bit difficult, so it might be worth it to enumerate use cases. Here are at least a few I am thinking of:
|
I think coroutines are out of the initial scope as MDC current infra relies on threads. (key1 to value1).asLoggingContextOf {
(key2 to value2).asLoggingContextOf {
...
}
} So the real question here is how required / strong is the use case. Currently, I don't use MDC (although I might start using it when support will be available ;-) It is always easier to start with partial API and add later. What do you think? |
I agree in cutting MDC support for coroutines the first iteration of this. There might be some way to handle it with The background for how I am hoping to migrate to MDC in one part of our application:
I'd like to get us moving forward for us by:
In our case, our key/value maps sometimes have 9-10 keys and values, so repeating
We can do all of that migration ourselves, but Kotlin-friendly |
ok, I will implement few flavors, let me know what you think. |
please see the commit let me know what you think, then I will push it to 1.4.9 |
👍 from me, looks good! |
version 1.4.9 deployed. |
* issue #21 - make the lib multiplatform - split to common/jvm/js - left all code in jvm at the moment - add build scripts * issue #31 - Add MDC support: withLoggingContext * merge to branch: issue #31 - Add MDC support: withLoggingContext * add documentation * rebase (#33) * issue #31 - Add MDC support: withLoggingContext * Update ChangleLog.md * Update ChangleLog.md * Update README.md * Rename ChangleLog.md to ChangeLog.md (#32) * update to kotlin 1.2.20 * split packages and gradle build * split packages and gradle build * split packages and gradle build * fix src root for jvm project * fix artifact build for jvm version
More details on coroutines with mdc are here: Kotlin/kotlinx.coroutines#119 |
coroutines support is now available, more details here: https://github.com/MicroUtils/kotlin-logging/wiki#mdc-and-threadscoroutines |
Consider adding some additional functions for managing MDC (Javadoc: https://www.slf4j.org/api/org/slf4j/MDC.html) by putting and removing keys
Additional consideration: it would be great to have it with coroutines
Docs: https://www.slf4j.org/manual.html#mdc
I don't have a concrete API proposal but here is some initial thoughts:
The text was updated successfully, but these errors were encountered: