log4j2-ttl-thread-context-map
log4j2-ttl-thread-context-map copied to clipboard
🌳 Log4j2 TTL ThreadContextMap, Log4j2 extension integrated TransmittableThreadLocal to MDC
🌳 Log4j2 TTL ThreadContextMap 🌳
- 🔧 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
- log4j2 documentation
- Mapped Diagnostic Context (MDC) support - slf4j official documentation
- Transmittable ThreadLocal(TTL), 📌 The missing Java™ std lib(simple & 0-dependency) for framework/middleware, provide an enhanced InheritableThreadLocal that transmits ThreadLocal value between threads even using thread pooling components.