Log4j Log at all Classes Level

2019-03-05 09:24发布

问题:

I am Debugging my Java Web Application Using Log4j, I need to Log At Class Level. I do not want to put a line for each Class in my log4j.properties file as I have hundreds of classes in my application like this:

log4j.logger.com.my.package.class1=DEBUG
log4j.logger.com.my.package.class2=DEBUG
log4j.logger.com.my.package.class3=DEBUG

Is there a one line setup to Achieve loggin for all the Classes?

回答1:

All loggers are ordered into a hierarchy, by its names. So you may to configure a parent logger ("log4j.logger.com.my.package" or root logger) and override configuration for some of child loggers if you need. See more at http://logging.apache.org/log4j/2.x/manual/architecture.html .



回答2:

LOG4J is designed in a pattern of systematic hierarchical structure, by the order of its names given.

Following image depicts the hierarchical representation of loggers

  • So if you need to override or re-configure the root node logger you need the log4j.logger.com.my.package in your case, and override the specific configuration of the child loggers.

Ref Link



标签: java log4j