apache / logging-log4j-kotlin

A Kotlin-friendly interface to log against the Log4j API
https://logging.apache.org/log4j/kotlin
Apache License 2.0
46 stars 12 forks source link

LOG4J2-2433 Coroutines Support #8

Closed rocketraman closed 4 years ago

rocketraman commented 5 years ago

Add support for coroutines by fixing LOG4J2-2433.

ThreadContext support is added to integrate the thread-local ThreadContext with coroutines context. Suspend functions inside lambda functions are not yet supported, because making the calls inline breaks caller location information. See discussion in https://github.com/apache/logging-log4j-kotlin/pull/7.

@jvz Can you take a look please?

jvz commented 5 years ago

That sounds better to me!

On Fri, Dec 21, 2018 at 16:47, Raman Gupta notifications@github.com wrote:

@rocketraman commented on this pull request.

In log4j-api-kotlin/src/main/kotlin/org/apache/logging/log4j/kotlin/ThreadContextContext.kt https://github.com/apache/logging-log4j-kotlin/pull/8#discussion_r243708005 :

    • logger.info { "..." } // The Thread context contains the mapping here
    • }
  • *
    • Note, that you cannot update Thread context from inside of the coroutine simply
    • using [ThreadContext.put]. These updates are going to be lost on the next suspension and
    • reinstalled to the Thread context that was captured or explicitly specified in
    • [contextMap] when this object was created on the next resumption.
    • Use withContext(ThreadContext()) { ... } to capture updated map of Thread keys and values
    • for the specified block of code.
  • *
    • @param contextMap the value of [Thread] context map.
    • Default value is the copy of the current thread's context map that is acquired via
    • [ThreadContext.getContext].
  • */ +public class ThreadContextContext(

I struggled with the name. It is actually a Kotlin coroutines "Context", for a Log4j "ThreadContext". Calling it ThreadContextHolder doesn't seem quite right either, as it does a bit more than just hold the log4j ThreadContext. How about CoroutineThreadContext?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/apache/logging-log4j-kotlin/pull/8#discussion_r243708005, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwS68B9B66XTsrM_789sRS_34xlNFxEks5u7WT2gaJpZM4ZJSG8 .

-- Matt Sicker boards@gmail.com

rocketraman commented 4 years ago

I'm curious about the garbage generating behavior of suspending and resuming the map and stack.

Good question. I added JMH in https://github.com/apache/logging-log4j-kotlin/pull/12 and IIUC JMH has the capability to benchmark/report on GC overhead. Would be cool to add such a benchmark.

rocketraman commented 4 years ago

Rebased and merged to master.

vladimirfx commented 3 years ago

Sorry for commenting closed pull request. When it might be released?

rocketraman commented 3 years ago

@jvz what do you think about a new release?

jvz commented 3 years ago

I've actually gotten back into using Kotlin lately thanks to Spinnaker using it in newer code. I'm pretty booked this weekend, but I can help get a release out after that. See if there's any other updates we should include.

vladimirfx commented 3 years ago

@jvz thank you for your time! Very waiting.