๐ณ Log4j2 TTL ThreadContextMap
June 9, 2023 ยท View on GitHub
๐ง Functions
๐ Enable the transmitting Log4j2 ThreadContext(ThreadLocal value) between threads even using thread pooling components by Transmittable ThreadLocal(TTL).
From
v1.4+upgrade toJava 8.
If you needJava 6support, use version1.3.x
๐ฅ 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
TtlThreadContextMapimplementation 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.4.0</version>
<scope>runtime</scope>
</dependency>
Find up-to-date 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.