0

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();
}
DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77
Yasin
  • 123
  • 1
  • 12
  • Can't you use `ThreadContext.push("ORDERID", "$123");`? I don't think there's a way to escape the $ sign. If you want more info: http://logging.apache.org/log4j/2.x/log4j-core/apidocs/org/apache/logging/log4j/core/lookup/StrSubstitutor.html – Eldelshell Apr 15 '19 at 13:12
  • If you don't mind having an space between you can use `pattern="ORDERID : $ ${ctx:ORDERID} %msg%n"` – Eldelshell Apr 15 '19 at 13:27
  • @Eldelshell thanks. I handle it thank for give document url. I have used ThreadContext.put instead of ThreadContext.push. İt is work. – Yasin Apr 15 '19 at 20:28

1 Answers1

0

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

Yasin
  • 123
  • 1
  • 12