I wish to filter certain logs if the "env" key in the ThreadContextMap
has a value of prod1
or qa1
.
I already have something like the following set up:
<Console name="prodOutput" target="SYSTEM_OUT">
<PatternLayout pattern="..."/>
<Filters>
<ThreadContextMapFilter onMatch="DENY" onMismatch="NEUTRAL" operator="or">
<KeyValuePair key="ENV" value="qa1"/>
<KeyValuePair key="ENV" value="prod1"/>
</ThreadContextMapFilter>
</Filters>
</Console>
But this code "hardcodes" the values prod1
& qa1
. In the spirit of making the code extensible, I want to filter out those logs if they match the regex of "prod\d+"
or "qa\d+"
.
Values that would match these regex's include "prod1"
, "qa2"
.
This is because we don't want those certain logs to appear on production & qa environments.
In the ThreadContextMap
, the key-value pairs we're checking for is ENV
-prod1
or ENV
-qa1
.
I searched StackOverflow as well as the log4j2 documentation but there doesn't seem to be any mention of how such a thing can be done.
Any ideas on how I can approach this or alternatives?