java 错误 StatusLogger 未找到 log4j2 配置文件。使用默认配置:仅将错误记录到控制台
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27116199/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console
提问by jaycee
I am trying to use log4j2 in my Ant build.xml to create executable .jar. The jar works fine but it seems like log4j2.xml is not being recognized. I currently have the file under src folder. and have classpath set in my build.xml as below. This happens for all my projects. What would be the proper directory to put log4j2.xml? Is there something other than adding it to classpath in build.xml to do?
我正在尝试在 Ant build.xml 中使用 log4j2 创建可执行文件 .jar。该 jar 工作正常,但似乎无法识别 log4j2.xml。我目前在 src 文件夹下有这个文件。并在我的 build.xml 中设置类路径,如下所示。这发生在我所有的项目中。放置 log4j2.xml 的正确目录是什么?除了将它添加到 build.xml 中的类路径之外,还有其他事情要做吗?
<path id = "classpath">
<pathelement location="${junitJar}/junit-4.11.jar"/>
<pathelement location="${junitJar}/hamcrest-core-1.3.jar" />
<pathelement location="${classes.dir}"/>
<pathelement location="${log4jJar}/log4j-api-2.1.jar" />
<pathelement location="${log4jJar}/log4j-core-2.1.jar" />
<pathelement location="${src.dir}/log4j2.xml" />
</path>
compile:
jar:
run:
[java] ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
[java] Hello World!
main:
BUILD SUCCESSFUL
Total time: 1 second
回答by Steve C
Changing the last pathelement to:
将最后一个路径元素更改为:
<pathelement location="${src.dir}/" />
will work, but in practice you should probably have this file somewhere else.
会工作,但实际上你应该在其他地方拥有这个文件。
In an ant build it's normal to copy these files into the classes directory so it gets included in the jar file.
在 ant 构建中,将这些文件复制到 classes 目录中是正常的,因此它会包含在 jar 文件中。