0

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?

2 Answers 2

3

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

log4j.additivity.SPECIAL_LOGGER=false
1
  • 1
    I did not know about that feature. A great answer and does exactly what I need. Thanks!
    – brabster
    Apr 2, 2012 at 13:25
0

I used this in my app to make it work. You need to create separate appender in your log4j.xml, something like this may help :

<appender name="myAppender" class="org.apache.log4j.DailyRollingFileAppender">
    <param name="file" value="logs/date.log" />     
    <param name="append" value="true" />
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d{HH:mm:ss z} %-5p [%c{1}] [%t] %C:%L - %m%n" />
    </layout>
</appender>

Using different params in appender, you can customize it as per your own way.

1
  • I am using appenders already, but I need to exclude from one. @adarshr's answer seems to be spot on for that.
    – brabster
    Apr 2, 2012 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.