我正在尝试在我的应用中设置log4j,而我的第三方JAR之一似乎以某种方式一直将我的日志级别设置为"OFF".仅在执行该库中的代码时才会发生.我不知道它如何做到这一点,因为我没有使用它知道名称的记录器,也没有使用根记录器.我为此花了5个小时,到目前为止,我唯一的成就就是获得超过9000的挫败感.
I'm trying to set up log4j in my app and one of my third party JARs seems to somehow keep turning my log level to "OFF". It only happens when code from that library is executed. I don't know how it can do this because I'm not using a logger it knows the name of, and I'm not using the root logger. I've spent 5 hours on this and so far my only achievement has been to acquire a frustration level of over 9000.
我在Windows 7 64位Java 6 u23上使用最新的Tomcat(7.0.37).
I'm using the latest Tomcat (7.0.37) on windows 7 64 bit, Java 6 u23.
log4j.properties:
log4j.properties:
log4j.logger.foo.bar.SearchAndReport=TRACE, stdout, file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=D:/logTest.log log4j.appender.file.MaxFileSize=100KB log4j.appender.file.MaxBackupIndex=1 log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=[%p] %d{dd MMM yyyy HH:mm:ss,SSS} - %C{2}.%M() - %m %n然后在我的Servlet中进行测试:
then in my Servlet for testing I have:
Logger log = Logger.getLogger(SearchAndReport.class); System.out.println(log.getLevel());此代码每次运行DoPost或DoGet时都会运行,并且级别一直保持在我设置的级别(TRACE)上,直到第三方代码运行并将其关闭为止.
This code runs every time a DoPost or DoGet is run, and the level stays on the level I set (TRACE) until the third party code runs and turns it to off.
我的问题是:
谢谢:)
推荐答案
Log4j配置未合并,似乎存在其他配置而不是您的配置被读取,或者该配置被覆盖.在JAR中嵌入log4j配置文件是许多类似问题的根源.
Log4j configurations are not merged, it seems that either the other configuration is present and is read instead of yours, or the configuration is overwritten. Embedding log4j config file in JAR is source of many similar problems.
您可以使用 org.apache.log4j.PropertyConfigurator 或 org.apache.log4j.xml.DOMConfigurator 在代码中重新加载配置.另外,请检查您的第三方代码是否未使用它们.
You can reload the configuration in your code using either org.apache.log4j.PropertyConfigurator or org.apache.log4j.xml.DOMConfigurator. Check also, if your third-party code isn't using them.
更多推荐
log4j干扰
发布评论