Angelo Fuchs
Angelo Fuchs

Reputation: 9941

Filter logger from one appender but not another

I have two appenders in my logging configuration. One of them sends E-Mail on ERROR Events.

A class, that I have no control over, spams ERROR messages. So I still want to have that messages but not in both appenders.

This is about my file (reduced to the stuff relevant here, afaics):

<appender name="Logfile">...</appender>
<appender name="sendMailOnError">...</appender>

<logger name="spammingClass">
    <level value="info"/>
</logger>

<root>
   <level value="debug"/>
   <appender-ref ref="Logfile"/>
   <appender-ref ref="sendMailOnError"/>
</root>

So, my guess is that I can somehow exclude spammingClass in sendMailOnError but I don't know how.

Btw. I use Java, but I would like to not write an own Filter class for this.

Upvotes: 2

Views: 929

Answers (2)

richardtz
richardtz

Reputation: 4993

You can use additivity, in your example change the spammingClass logger to :

<logger name="spammingClass" additivity="false">
    <level value="info"/>
</logger>

and it will do the trick.

Upvotes: -1

barfuin
barfuin

Reputation: 17474

Yes, by specifying appenders for spammingClass and setting additivity to false:

<logger name="spammingClass" additivity="false">
    <level value="info"/>
    <appender-ref ref="Logfile"/>
</logger>

Upvotes: 3

Related Questions