Additivity is not going to work in your case, coz additivity is controlling a specific logger not to inherit parent's appender.
In your config, you are setting logger foo
to have additivity
= false, which means, unless you are using foo
or its children loggers for your logging, you will still follow root loggers' config. (I can't see your root logger config in your post, I suspect it is referring to both appenders). From your quoted code, you are using the root logger for your logging, the configuration of foo
logger simply won't take effect.
There are two solution I can suggest:
- For all log messages you log with
TEST_LOG
marker, make sure you log it usingfoo
logger. or, - If you need to use any logger for your
TEST_LOG
messages, then you should reconfigure your appender, so that yourGLOBAL
file appender accept anything BUTTEST_LOG
. (Currently you are only denyingSELL_FAILURE
marker)
Correct solution depends on your actual requirement. Make sure you understand the basic concepts so you can choose the right solution for you.
Edit:
First, even with your "correct" config you mentioned in the comment, the issue of different loggers still holds. Which mean, coz you are using root logger to do your logging, your config for foo
logger has nothing to do with your log message, and additivity is out of picture in your case.
I am not using Log4J2, a brief check on the usage of filter lead me to two issues:
First, I believe proper way to define more than 1 filter is to make use of Composite Filter (which means defining in a <Filters>
element, though I don't quite get the syntax from Log4J's doc).
Second, even you define it in composite filter, your config will still have problem. When a log event is having INFO or higher level, you declare in filter it is an ACCEPT
or DENY
which will prohibit subsequent filter evaluation. If you want to log messages with INFO
and not containing TEST_LOG
marker, you should do something like:
<MarkerFilter marker="TEST_LOG" onMatch="DENY" onMismatch="NETURAL"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
NEUTRAL
means current filter cannot determine whether to accept or deny the message, and will evaluate next filter to determine it.