Log4j2 truncating / extract value of printed from MDC

13 views Asked by At

We are using Slf4j backed by log4j2 in one of our app, where framework adds some value in MDC which we want to either truncate or use portion of it. Example say

workflowId=abc-efg-workflowId-23213

where we want to write value in log as

workflow=%X{workflowId}{SomeExtractionPattern} resulting into output as workflow=efg 

Since code snippet doing same is part of private functions, we can't modify / extend same directly.

Alternatively thought of reading value from MDC in code and setting that back to MDC as new Key, however avoiding that route as there can be multiple thread hops which framework is taking care of Keeping that value in context.

Is their some way by which we can extract / truncate value retrieved from MDC context in logs similar to conversion pattern like %c{1}

0

There are 0 answers