Search code examples
javalog4jappender

How do I direct logging output to exclusively to different loggers with Log4J


I'd like to use Log4J to send output of a very specific nature to a different log from that specified for everything else. Right now, I have a log4j.properties that looks a bit like:

log4j.rootLogger=INFO,catchall
log4j.logger.SPECIAL_LOGGER=INFO,specials
... catchall, specials appenders defined

I want ONLY the output from the Logger SPECIAL_LOGGER in the specials appender - easy enough - but I DO NOT want the output from SPECIAL_LOGGER in my catchall appender. I think this means I can't do what I need with log levels.

Any ideas?


Solution

  • Just set an appropriate additivity. Add this line to your log4j configuration.

    log4j.additivity.SPECIAL_LOGGER=false