Duncan Krebs
Duncan Krebs

Reputation: 3502

How do I disable log4j2.xml additivity in appender refs within a logger xml tag

I've done my research before posting this question and my issue as to do with my not correctly using the additivity attribute, below is a snippet from my log4j2.xml and what I'm trying to achieve is each appender ref defined within the logger should only append logs of the level it defines but all appenders are getting all log messages appended regardless of log level, so for example the debug logger is still getting error messages which i don't want. Any input would be greatly appreciated.

<Logger name="com.mycompnay" level="INFO" additivity="false">

    <AppenderRef ref="CoreInfo" level="INFO"/>
    <AppenderRef ref="CoreDebug" level="DEBUG"/>
    <AppenderRef ref="CoreWarning" level="WARNING"/>
    <AppenderRef ref="CoreError" level="ERROR"/>

</Logger>

Upvotes: 0

Views: 626

Answers (1)

Duncan Krebs
Duncan Krebs

Reputation: 3502

I found the solution to this, instead of setting the log level on the appender ref, in the appender declaration you can do something like this to ensure it only logs debug messages which you can change to any log level you want. Took a while to find this!

<LevelRangeFilter minLevel="DEBUG" maxLevel="DEBUG" onMatch="ACCEPT" onMismatch="DENY"/>

Upvotes: 1

Related Questions