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

185 Views Asked by At

I'm having trouble getting a log message to display the right way. I'm using this Log4J pattern layout:

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

I want to see output like:

ORDERID: 123 Test Context

But this is the output I am getting:

ORDERID : ${ctx:ORDERID} Test Context

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();
}
1

There are 1 best solutions below

0
Yasin On

I have used ThreadContext.put instead of ThreadContext.push. İt is work.

ThreadContext.put("ORDERID", "123"); instead of ThreadContext.push("ORDERID", "123");

Result Log Text Url

enter image description here