log4j logging twice

For those use XML format:

<logger name="package.class" additivity="false">
    <level value="info" />
    <appender-ref ref="file" />
    <appender-ref ref="console" />
</logger>

Note: By default, Loggers have their additivity flag set to true.


Looks like your messages are being logged once by the root logger and again by the specific logger as you may have both the appenders configured (may be at different places -in a properties file and then in code).

This can be solved by setting additivity to false on your logger. Log4j manual mentions additivity in the Appenders and Layout section.Check that out


Agree with atlantis.

log4j.rootCategory=INFO, console
log4j.logger.org.hibernate=INFO

The above property settings will cause double logging.

However adding

log4j.additivity.org.hibernate=false

fixed the issue.

Check out page 62 of this book. http://books.google.com/books?id=hZBimlxiyAcC&printsec=frontcover#v=onepage&q&f=false

Tags:

Logging

Log4J