How we can setup pattern for logback-access.xml inside MDC and make use of MDC value inside <pattern></pattern>

Viewed 224

So, I am trying to achieve one scenario. I want to define a customizable pattern for my logback-access.xml file or logabck.xml file. I am setting up log pattern value in MDC and try to make use of this pattern in block.

I am facing then two scenarios:

  • For logback-access.xml I am seeing parse error for that MDC variable.

  • For logback.xml I am getting pattern value logged in console. So, If I am setting up value as: MDC.put("console_pattern", "%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n"); I should get a proper format log if I set pattern as: %X{console_pattern}

    Result I am getting in console should be a proper log statement, but I am getting %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n in log response.

I want to setup pattern value in MDC and instead of hardcoding pattern I want to access through MDC format. That's my actual ask.

Can anyone please help in this. Thanks in advance.

0 Answers
Related