Skip to content

Instantly share code, notes, and snippets.

@pavelaizen
Created March 26, 2018 09:00
Show Gist options
  • Save pavelaizen/26ba7f458f805625c869941d4d60ac3e to your computer and use it in GitHub Desktop.
Save pavelaizen/26ba7f458f805625c869941d4d60ac3e to your computer and use it in GitHub Desktop.
import org.apache.logging.log4j.ThreadContext
import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
class Log4jExecutor : ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
LinkedBlockingQueue()) {
override fun beforeExecute(t: Thread, r: Runnable) {
refreshKeys()
super.beforeExecute(t, r)
}
private fun refreshKeys() = ThreadContext.putAll(LogEventConstants.getThreadContextKeys())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment