I would like to filter log events coming from a specific component of a 3rd party library, based on the content of the log message. I only want this filtering to be applied when the log event is generated by a specific logger: "org.restlet.Component.LogService". The filtering itself is just a basic match against the log event message.
I have a central AsyncAppender that logs to multiple appenders. In the case that events coming from LogService are not filtered out, I'd like them to be treated the same as they are now -- that is, get sent to the AsyncAppender. I don't want to add a filter to the AsyncAppender, because this seems terribly inefficient (I don't need to filter ALL events, just the ones coming from the LogService logger).
So what I've tried to do is associate LogService logger with a custom Appender, which in turn is associated with a custom Filter:
<appender name="filtered" class="mystuff.FilteredAppender">
<filter class="mystuff.EventFilter"/>
<appender-ref ref="ASYNC"/>
</appender>
<logger name="org.restlet.Component.LogService">
<appender-ref ref="filtered"/>
</logger>
The error I currently get...
log4j:ERROR No layout set for the appender named [filtered].
...tells me there's something wrong with my design: I don't think my custom appender should care about layout, since really it just needs to pass or not pass the log event along. Also, this approach requires two custom classes, and one of them (mystuff.FilteredAppender) adds no value at all -- it's only there to hold the custom Filter.
I'd love to do something much cleaner like...
<logger name="org.restlet.Component.LogService">
<filter class="mystuff.EventFilter"/>
</logger>
...but this is apparently not supported by the log4j framework.
Is there a good clean way to do event filtering the way I want to do it?