简体   繁体   English

log4j - 为不同的包/类设置不同的日志级别

[英]log4j - set different loglevel for different packages/classes

I use log4j for logging and i want to print all logger.debug statements in a particular class / selected package.我使用 log4j 进行日志记录,我想打印特定类/选定包中的所有 logger.debug 语句。

i set the cfg as below>我将 cfg 设置如下>

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 ?这不是正确的方法吗?

Instead of using 'category' use 'logger'.而不是使用“类别”使用“记录器”。 Hence, these level are configured for entire log4j, and does not depend on appender, etc.因此,这些级别是为整个 log4j 配置的,不依赖于 appender 等。

Following change works:以下更改有效:

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

Copying from my current log4j.properties:从我当前的 log4j.properties 复制:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM