Mar 12 2008

How to use log4j

Tag: Java, log4jYogesh @ 9:30 am

Here is a simple example showing how to log using Log4j.


Mar 07 2008

Log4j logging everything twice

Tag: log4jYogesh @ 11:29 am

This is related to the problem mentioned in this post

old post

and that solves this issue too.


Mar 05 2008

Log4j logging in system out

Tag: log4jYogesh @ 12:24 pm

Sometimes log4j decides to log in system out in addition to whatever root appenders you might be using. This is some problem which gave me serious headaches.

So heres what is happening, log4j by default logs to the custom categories (whatever you have specified) and then root logger as well!

To prevent this you have to set the custom categories additivity to false, so that it doesn't use the root logger.

An example:

<category name="customname" additivity="false">
<priority value="DEBUG"/>
<appender-ref ref="RollingFileOutput"/>
</category>

if you are using a property file,

log4j.category.additivity.myCategory=false

where myCategory is the name of the custom category you might have created.