views:

388

answers:

2

Suppose I have these packages in my application - foo.bar and foo.foobar, And I want to send all log4j log messages that are coming from foo.bar package to foobar.log file and the log messages coming from foo.foobar to foofoobar.log file, how should I configure the log4j.xml file?

+4  A: 

You can use appender-ref in the logger configuration:

<logger name="foo.bar">
    <level value="debug"/>
    <appender-ref ref="FILE1" />
</logger>

Have a look here for full examples.

kgiannakakis
A: 

I suggest also to set additivty to "false" when you have overlapping hierarchies and don't want duplicate log messages.

i.e:

<logger name="foo.bar">
    <level value="debug"/>
    <appender-ref ref="FILE1" />
</logger>
<logger name="foo.bar.xyz" additivity="false">
    <level value="debug"/>
    <appender-ref ref="FILE2" />
</logger>

This way messages directed to FILE2 won't be written to FILE1

Megadix