我怎样才能知道Log4j从哪里获取它的配置呢?[英] How can I tell where is Log4j picking its configuration from

本文是小编为大家收集整理的关于我怎样才能知道Log4j从哪里获取它的配置呢?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

有没有办法弄清楚 Log4J 从哪里挑选配置文件?我试图更改我的 log4j.xml,但更改并未反映在 Log4j 行为中.我删除了 log4j.xml,有趣的是,Log4J 仍在处理旧行为.所以它必须选择一些在我的命名空间中可用的配置文件.但问题是我怎样才能弄清楚是哪一个.有没有办法做到这一点?jar 等有很多不同的依赖项,因此其中之一必须包含覆盖我的更改的 log4j.xml 或 log4j.properties.有什么想法吗?

推荐答案

在运行应用程序时,您可以设置系统属性-Dlog4j.debug.在这种情况下,log4j 将产生调试输出,并告诉您它如何解析 log4j.xml 的路径,例如:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Using URL [file:/C:/develop/workspace/foobar/target/classes/log4j.xml] for automatic log4j configuration.
log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator

要显式设置路径,请使用 此处所述的系统属性 -Dlog4j.configuration=file:c:/pathToFile.

本文地址:https://www.itbaoku.cn/post/1574945.html

问题描述

Is there a way to figure out where is Log4J picking the configuration file from? I tried to change my log4j.xml and the changes were not reflected in Log4j behaviour. I deleted log4j.xml and funnily enough, Log4J is still working with the old behaviour. So it must be picking some configuration file which is available in my namespace. But the question is how can I figure out which one. Is there a way to do that? there are so many different dependencies on jars etc, so one of them must contains a log4j.xml or log4j.properties that is overriding my changes. Any ideas?

推荐答案

When running your application you can set the system property -Dlog4j.debug. log4j will produce debug output in this case and tells you about how it resolves the path to the log4j.xml, e.g.:

log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@11b86e7.
log4j: Using URL [file:/C:/develop/workspace/foobar/target/classes/log4j.xml] for automatic log4j configuration.
log4j: Preferred configurator class: org.apache.log4j.xml.DOMConfigurator

To set a path explicit use the system property -Dlog4j.configuration=file:c:/pathToFile as described here.