0

If I have a KeyValuePair in my JsonLayout appender, and that pair is not set in the MDC, is there a way to exclude the value from the logs?

Mike
  • 609
  • 12
  • 36

2 Answers2

1

I used a routing appender with a js script. The script grabs the variable into a variable and compares it to itself. If the value is equal to its own replacer - it means it wasn't replaced. In this case, I don't route to the appender that has that KeyValuePair - I route to another one that doesn't.

Mike
  • 609
  • 12
  • 36
1

In Java,

You can use ':-' for null value in log4j2.xml

Example:

<KeyValuePair key="traceId" value="$${ctx:traceId:-}"/>
WindBlad3
  • 36
  • 4