简体   繁体   English

如何在日志文本上将OrderId显示为Log4j模式布局

[英]How can I show OrderId on log text as Log4j pattern layout

I'm having trouble getting a log message to display the right way. 我无法获取日志消息以显示正确的方式。 I'm using this Log4J pattern layout: 我正在使用这个Log4J模式布局:

pattern="ORDERID : $${ctx:ORDERID} %msg%n"

I want to see output like: 我想看看输出如下:

ORDERID: 123 Test Context ORDERID:123测试上下文

But this is the output I am getting: 但这是我得到的输出:

ORDERID : ${ctx:ORDERID} Test Context ORDERID:$ {ctx:ORDERID}测试上下文

This is the code that's generating the log message: 这是生成日志消息的代码:

@Test
public void testThreadContext() {
    ThreadContext.push("Message only");
    ThreadContext.push("int", 1);
    ThreadContext.push("int-long-string", 1, 2L, "3");
    ThreadContext.push("ORDERID", "123");
    logger.info("Test Context");
    ThreadContext.clearAll();
}

I have used ThreadContext.put instead of ThreadContext.push. 我使用ThreadContext.put而不是ThreadContext.push。 İt is work. 是工作。

ThreadContext.put("ORDERID", "123"); ThreadContext.put(“ORDERID”,“123”); instead of ThreadContext.push("ORDERID", "123"); 而不是ThreadContext.push(“ORDERID”,“123”);

Result Log Text Url 结果日志文本URL

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM