简体   繁体   English

找不到Log4j2.xml但是log4j2-test.xml是

[英]Log4j2.xml not found but log4j2-test.xml is

I'm upgrading from log4j 1.x to log4j 2, and have updated my log4j.xml configuration file to a new log4j2.xml configuration. 我正在从log4j 1.x升级到log4j 2,并将我的log4j.xml配置文件更新为新的log4j2.xml配置。 I'm running maven, spring, and mule. 我正在跑maven,spring和mule。

When running a test maven build, the log4j2.xml file is not being picked up. 运行测试maven构建时,不会拾取log4j2.xml文件。 However, if I rename the file log4j2-test.xml, it gets picked up (for instance the console logger with a custom PatternLayout works correctly the second case, but in the first case the default config is used). 但是,如果我重命名文件log4j2-test.xml,它将被拾取(例如,具有自定义PatternLayout的控制台记录器在第二种情况下正常工作,但在第一种情况下使用默认配置)。

Why would log4j pick up the log4j2-test.xml but not the log4j2.xml? 为什么log4j会选择log4j2-test.xml而不是log4j2.xml?

Since log4j2-test.xml has a higher load precedence than log4j2.xml , you probably have another log4j2 configuration file somewhere on your classpath that's overriding your log4j2.xml . 由于log4j2-test.xml加载优先级高于log4j2.xml ,因此您的类路径上的某个地方可能还有另一个log4j2配置文件,它覆盖了log4j2.xml Try finding the location of which conf file is getting pulled by having the following code execute when you run your maven test build: 通过在运行maven测试版本时执行以下代码,尝试查找获取conf文件的位置:

for (String confFile : Arrays.asList("/log4j2-test.xml", "/log4j2.yaml", "/log4j2.yml", "/log4j2.json", "/log4j2.jsn", "/log4j2.xml")) {
    URL resource = YourTestClass.class.getResource(confFile);
    if (resource != null) {
        System.out.format("found %s in: %s\n", confFile, resource.getFile());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM