问题描述
有没有办法弄清楚 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.
问题描述
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.