某些记录器未打印 log4j2 MDC 数据
通过 log4j-1.2-api 桥切换到 log4j2 后,我注意到某些日志行中缺少 MDC 数据。这些行来自同一类中的单独记录器。令人费解的是,这种情况是随机发生的——有时 MDC 数据出现,有时则不出现。关于为什么会发生这种不一致的任何想法?
After switching to log4j2 via the log4j-1.2-api bridge, I've noticed that MDC data is missing from some log lines. These lines come from a separate logger in the same class. What's puzzling is that this happens randomly – sometimes the MDC data appears, and other times it doesn't. Any ideas on why this inconsistency is happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果有人遇到同样的问题,这是因为 log4j 桥在后台使用 ThreadContext 来重定向 MDC 调用,并且 log4j2 中默认情况下不会激活线程继承,因此要使其激活,您可以添加 log4j2.component .properties 文件并将此条目添加到其中:
If anybody gets here with the same problem this is because the log4j bridge uses ThreadContext in the background to redirect MDC calls and thread inheritance is not activated by default in the log4j2, thus to make it active you can add a log4j2.component.properties file and add this entry to it: