Spring Cloud Sleuth + log4j2 [英] Spring Cloud Sleuth + log4j2

查看:92
本文介绍了Spring Cloud Sleuth + log4j2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一些微服务使用 log4j2 作为记录器.Spring Cloud Sleuth 支持 logback.在这种情况下,我如何使用 Sleuth 进行分布式跟踪.我知道在 log4j2 中使用侦探,我必须实现某些类.我试过这个,但没有运气.请帮忙

Some of my microservices use log4j2 as logger. Spring cloud Sleuth has support for logback. How can I use Sleuth to get distributed tracing in this scenario. I understand to use sleuth with log4j2, I have to implement certain class. I tried this but no luck. Please help

推荐答案

Sleuth 将 traceId 和 spanId 放在 MDC(映射诊断上下文)中.

Sleuth puts the traceId and spanId in the MDC(Mapped Diagnostic Context).

可以使用%X查看MDC键值对,与Sleuth相关的键有traceIdspanIdparentId, spanExportable.

You can use %X to check the MDC key value pairs, and Sleuth related keys are traceId, spanId, parentId, spanExportable.

要模拟 logback 默认样式,只需手动将以下代码段添加到您的 PatternLayout 中:

To simulate the logback default style, just maunally add below snippet into your PatternLayout:

[${APP_NAME},%X{traceId},%X{spanId},%X{spanExportable}]

${APP_NAME} 就是你的 spring:application:name.

这篇关于Spring Cloud Sleuth + log4j2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆