brabster
brabster

Reputation: 43560

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?

Upvotes: 0

Views: 311

Answers (2)

Ved
Ved

Reputation: 8767

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.

Upvotes: 0

adarshr
adarshr

Reputation: 62593

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

log4j.additivity.SPECIAL_LOGGER=false

Upvotes: 3

Related Questions