我怎么知道Log4j从哪里挑选配置 [英] How can I tell where is Log4j picking its configuration from

查看:76
本文介绍了我怎么知道Log4j从哪里挑选配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有办法弄清楚Log4J从何处挑选配置文件? 我尝试更改log4j.xml,但更改未反映在Log4j行为中.我删除了log4j.xml,很有趣的是,Log4J仍在处理旧的行为.因此,它必须选择一些在我的命名空间中可用的配置文件.但是问题是我该如何找出哪一个.有没有办法做到这一点? jars等上有很多不同的依赖项,因此其中之一必须包含覆盖我的更改的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,如此处所述. /p>

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.

这篇关于我怎么知道Log4j从哪里挑选配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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