log4j干扰-级别保持设置为"OFF". [英] log4j interference - level keeps being set to "OFF"

查看:29
本文介绍了log4j干扰-级别保持设置为"OFF".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中设置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.com.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.

我的问题是:

  1. 另一个记录器如何干扰我命名并设置的记录器?
  2. 如何阻止这种情况发生,并强制设置我设置的水平?

谢谢:)

推荐答案

  1. Log4j配置未合并,似乎存在其他配置而不是您的配置被读取,或者该配置被覆盖.在JAR中嵌入log4j配置文件是许多类似问题的根源.

  1. 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干扰-级别保持设置为"OFF".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆