56

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 ?

Sebastian
  • 5,721
  • 3
  • 43
  • 69
jch
  • 1,155
  • 3
  • 14
  • 27

2 Answers2

91

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
ankitjaininfo
  • 11,961
  • 7
  • 52
  • 75
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • 1
    I know I'm late joining the party, but do you happen to have a link to the relevant page in the official docs explaining these settings, by any chance? :) I can see the value is in my `log4j.properties` in tomcat's `webapps/myProject/WEB-INF/classes/`folder, but I just don't get any `DEBUG` output in my IntelliJ console... – Christian Jul 12 '17 at 17:42
  • 1
    What is meant by "package"? Granted, the logger name is often a class name, but in reality, it is just a string with .'s in it. Will the logger look for properties with all possible prefixes, or just the whole string and everything before the last . ? – Karsten Spang Mar 18 '20 at 11:07
28

Copying from my current log4j.properties:

log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.sql=info
Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 18
    Not only was I looking up how to change the logger level for different packages, but those were actually the packages I was looking to change the logger level for! – CorayThan May 13 '13 at 17:32