First I just want to mention one item before I answer your question. You wrote:
logs INFO, WARNING, ERROR and FATAL. So it seams that NEUTRAL, which
is the default value, means: don't filter out anything and let the log
go through.
That's not entirely accurate in that TRACE and DEBUG level events are not published because they are filtered out by the default value of the onMismatch parameter of your filter. According to the ThresholdFilter documentation:
onMismatch [is the] Action to take when the filter does not match. May be ACCEPT, DENY or NEUTRAL. The default value is DENY.
Getting back to your question, the difference between NEUTRAL
and ACCEPT
when using a single filter is nothing, they behave the same. When you use a CompositeFilter, however, there's a huge difference.
Let's say I have a simple class that generates some logs:
package example;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
public class SomeClass {
private static final Logger log = LogManager.getLogger();
private static final Marker FLOW_MARKER = MarkerManager.getMarker("FLOW");
public static void main(String[] args){
if(log.isDebugEnabled())
log.debug(FLOW_MARKER,"This is some debug!");
log.info("Here's some info!");
log.error("Some erorr happened!");
log.trace("Trace message, yeah!");
}
}
Now let's say I have a log4j2 configuration that includes a CompositeFilter that contains 2 filters:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
<Filters>
<ThresholdFilter level="INFO" onMatch="NEUTRAL" onMismatch="NEUTRAL"/>
<MarkerFilter marker="FLOW" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</Console>
</Appenders>
<Loggers>
<Root level="trace">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
When we run this simple class we get the following output:
22:35:31.666 [main] DEBUG example.SomeClass - This is some debug!
If we now change the ThresholdFilter's onMatch
parameter to ACCEPT
:
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
We will get this output instead:
22:36:00.939 [main] DEBUG example.SomeClass - This is some debug!
22:36:00.941 [main] INFO example.SomeClass - Here's some info!
22:36:00.941 [main] ERROR example.SomeClass - Some erorr happened!
At first, since the ThresholdFilter
did not accept or deny any log events they all pass through to the MarkerFilter
and are denied if they do not have the FLOW
marker. When we changed the ThresholdFilter
to accept matching events the INFO
and ERROR
level events were accepted before reaching the MarkerFilter
and therefore were published. We still see the log message from the DEBUG
level event that was not denied by the ThresholdFilter
because ThresholdFilter
is NEUTRAL
to mismatches and MarkerFilter
accepted the event because it had the FLOW
marker.