java 只指定一些包有调试输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6796411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specify only some packages to have debug output
提问by Smolda
I want to log some behavior of my web application which also implements hibernate, spring and so on. When I tried to implement log4j logger from apache I had some troubles.
我想记录我的 Web 应用程序的一些行为,它也实现了休眠、弹簧等。当我尝试从 apache 实现 log4j 记录器时,我遇到了一些麻烦。
When I turn on logger it is also debugging hibernate and spring which I don't want. I tried to configure properties file to the specify the package of my project but it does not work.
当我打开记录器时,它也在调试我不想要的休眠和弹簧。我试图配置属性文件来指定我的项目包,但它不起作用。
Here is my code of property file:
这是我的属性文件代码:
log4j.rootCategory=ERROR, O
log4j.category.com.my.package= DEBUG, FILE, O
log4j.appender.FILE=org.apache.log4j.RollingFileAppender
log4j.appender.FILE.File=log/logger.log
log4j.appender.O=org.apache.log4j.ConsoleAppender
.... and some layout
It works when I switch rootCategory = DEBUG
but it is also debugging the hibernate and spring as I said.
它在我切换时工作,rootCategory = DEBUG
但正如我所说的,它也在调试休眠和弹簧。
回答by Bozho
Yes, you have to specfiy the log level per package:
是的,您必须指定每个包的日志级别:
log4j.logger.org.hibernate=info
log4j.logger.org.springframework=info
log4j.logger.com.yourapplication=debug
Note that you should switch from categories (obsolete) to loggers. So log4j.rootLogger=...
请注意,您应该从类别(过时)切换到记录器。所以log4j.rootLogger=...
回答by chahuistle
You would need to know the name of the loggers that are actually writing stuff... The simplest way is to set the root category to error:
您需要知道实际编写内容的记录器的名称...最简单的方法是将根类别设置为错误:
log4j.rootCategory=ERROR, 0
Then set the level for your logs accordingly:
然后相应地设置日志的级别:
log4j.com.your.package=DEBUG...
Setting the rootCategory
to DEBUG
will turn everythingto DEBUG
, unless you specifically configure a logger otherwise.
设置rootCategory
toDEBUG
会将所有内容变为DEBUG
,除非您另外专门配置了记录器。
B.T.W, this is NOT a hibernate issue, this is related to how you are configuring your logger.
顺便说一句,这不是休眠问题,这与您配置记录器的方式有关。