com.ofpay:logback-mdc-ttl

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

License

License

Categories

Categories

Logback Application Layer Libs Logging
GroupId

GroupId

com.ofpay
ArtifactId

ArtifactId

logback-mdc-ttl
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Source Code Management

Source Code Management

https://github.com/ofpay/logback-mdc-ttl.git

Download logback-mdc-ttl

How to add to project

<!-- https://jarcasting.com/artifacts/com.ofpay/logback-mdc-ttl/ -->
<dependency>
    <groupId>com.ofpay</groupId>
    <artifactId>logback-mdc-ttl</artifactId>
    <version>1.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.ofpay/logback-mdc-ttl/
implementation 'com.ofpay:logback-mdc-ttl:1.0.2'
// https://jarcasting.com/artifacts/com.ofpay/logback-mdc-ttl/
implementation ("com.ofpay:logback-mdc-ttl:1.0.2")
'com.ofpay:logback-mdc-ttl:jar:1.0.2'
<dependency org="com.ofpay" name="logback-mdc-ttl" rev="1.0.2">
  <artifact name="logback-mdc-ttl" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.ofpay', module='logback-mdc-ttl', version='1.0.2')
)
libraryDependencies += "com.ofpay" % "logback-mdc-ttl" % "1.0.2"
[com.ofpay/logback-mdc-ttl "1.0.2"]

Dependencies

compile (1)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.0.12

provided (1)

Group / Artifact Type Version
com.alibaba : transmittable-thread-local jar 2.2.0

Project Modules

There are no modules declared in this project.

logback-mdc-ttl

Maven Central GitHub release License

👉 logback扩展,支持跨线程池的mdc跟踪。

实现上集成使用了Transmittable ThreadLocal(TTL) :在使用线程池等会缓存线程的组件情况下,提供ThreadLocal值的传递功能,解决异步执行时上下文传递的问题。支持JDK 9/8/7/6。

示例

1.项目依赖

<dependency>
    <groupId>com.ofpay</groupId>
    <artifactId>logback-mdc-ttl</artifactId>
    <version>1.0.2</version>
</dependency>

2. 在Java的启动参数加上:

  • -Xbootclasspath/a:/path/to/transmittable-thread-local-2.x.x.jar
  • -javaagent:/path/to/transmittable-thread-local-2.x.x.jar

3. 在logback配置文件中增加TtlMdcListener

<?xml version="1.0" encoding="UTF-8"?>
<configuration >
    <!-- ...(略) -->
    <contextListener class="com.ofpay.logback.TtlMdcListener"/>

    <!--例子:  %X{uuid} 支持在跨线程池时传递-->
    <property scope="context" name="APP_PATTERN"
              value='%d{yyyy-MM-dd HH:mm:ss.SSS}|%X{uuid}|%level|%M|%C\:%L|%thread|%replace(%.-2000msg){"(\r|\n)","\t"}|"%.-2000ex{full}"%n'/>
</configuration>
com.ofpay

Versions

Version
1.0.2