log4j - set different loglevel for different packages/classes

JavaLog4j

Java Problem Overview


I use log4j for logging and i want to print all logger.debug statements in a particular class / selected package.

i set the cfg as below>

log4j.category.my.pkg=info
log4j.category.my.pkg.ab.class1=debug

but still only info messages are shown..

is this not the right way ?

Java Solutions


Solution 1 - Java

Instead of using 'category' use 'logger'. Hence, these level are configured for entire log4j, and does not depend on appender, etc.

Following change works:

log4j.logger.my.pkg=info
log4j.logger.my.pkg.ab.class1=debug

Solution 2 - Java

Copying from my current log4j.properties:

log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.sql=info

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionjchView Question on Stackoverflow
Solution 1 - JavadogbaneView Answer on Stackoverflow
Solution 2 - JavaBozhoView Answer on Stackoverflow