log4j.xml的放置位置 [英] Where to place log4j.xml
问题描述
我们如何指定在尝试查找xml配置文件时必须查看log4j的信息?
How can we specify were log4j has to look at when trying to find its xml configuration file ?
似乎默认情况下,log4j会查看类文件夹的根,我可以说使用debug log4j功能并从IDE运行我的应用程序.
It seems that by default, log4j looks into the root of a class folder, I can say that using the debug log4j functionality and running my application from the IDE.
但是,我的jar中不再有任何类文件夹. log4j.xml文件位于jar的根目录.
However, I don't have any class folder in my jar anymore. And the log4j.xml file is at the root of the jar.
我已经尝试设置-Dlog4j.configuration = log4j.xml选项,但是它不起作用.
I have already tried to set the option -Dlog4j.configuration=log4j.xml but it doesn't work.
这是我目前的应用程序的全局结构:
Here is the global structure of my application at the moment :
- com
- lib
- meta-inf
- log4j.xml
推荐答案
它使用CLASSPATH查找log4j.xml.如果log4j找不到任何配置文件,它将向控制台发送错误.如果您没有看到任何此类错误,则可能是找到了一个可能不是您正在编辑的配置文件.有一个命令行选项可强制Log4J报告其正在使用的配置文件的路径.
It finds the log4j.xml using the CLASSPATH. If log4j doesn't find any config file, it will send an error to the console. If you don't see any such error then it is likely that it is finding a config file which may not be the one you are editing. There is a command-line option to force Log4J to report the path of the config file it is using.
来自 http://wiki.apache.org/logging-log4j/Log4jConfigurationHelp
如果使用"-Dlog4j.debug"运行,则 log4j将打印出符合标准的信息 告诉它如何尝试的输出 自行配置.通过那看 会告诉您它在寻找什么 配置文件.
If you run with "-Dlog4j.debug" then log4j will print out info to standard output telling how it is trying to configure itself. Looking through that will tell you where it is looking for the config file.
这篇关于log4j.xml的放置位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!