As in log4j we have an option to set a default value against an MDC key like this - mdc{key:-defaultVal}
Do we have something similar in log4j 2 ?
Looking in MdcPatternConverter
it does not have support for default value.
There is open Jira ticket on that Tickt
I find that you can also use this: ${ctx:<key>:-<default_value>}
While there is no way to set a default with the %X
pattern, there are the %equals
and %equalsIgnoreCase
patterns which can be used for something equivalent.
%equals{%X{<key>}}{}{<default>}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With