log4j2-ttl-thread-context-map icon indicating copy to clipboard operation
log4j2-ttl-thread-context-map copied to clipboard

🌳 Log4j2 TTL ThreadContextMap, Log4j2 extension integrated TransmittableThreadLocal to MDC

🌳 Log4j2 TTL ThreadContextMap 🌳

Build Status Coverage Status Maven Central GitHub release
License GitHub Stars GitHub Forks GitHub repo dependents GitHub issues


  • 🔧 Functions
  • 👥 Usage
  • 🏃 Run Demo
  • 🍪 Dependency
  • 📚 Related resources

🔧 Functions

👉 Enable the transmitting Log4j2 ThreadContext(ThreadLocal value) between threads even using thread pooling components by Transmittable ThreadLocal(TTL).

Tested and support all log4j2 version(2.0 ~ 2.14) and java version 6 ~ 13.

👥 Usage

Just add this dependency into your project to activate the Log4j2 TTL ThreadContextMap. ✨

🏃 Run Demo

Run Demo Code

./mvnw clean test-compile -Dexec.classpathScope=test -Dexec.mainClass=com.alibaba.ttl.log4j2.Log4j2Demo exec:java

./mvnw clean test-compile -Dexec.classpathScope=test -Dexec.mainClass=com.alibaba.ttl.log4j2.Slf4jMdcDemo exec:java
  • Log4j2Demo.java
  • Slf4jMdcDemo.java
  • TtlThreadContextMap implementation class: TtlThreadContextMap.java.

🍪 Dependency

<!--
    because this dependency is implemented by log4j2 runtime extension
    that will never be used by biz code,
    set scope to *runtime*.
-->
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>log4j2-ttl-thread-context-map</artifactId>
    <version>1.3.3</version>
    <scope>runtime</scope>
</dependency>

Find available versions at search.maven.org.

📚 Related resources