log4j干扰

编程入门 行业动态 更新时间:2024-10-25 07:24:08
本文介绍了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.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干扰

    本文发布于:2023-10-22 08:33:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1516992.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:干扰   log4j

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!