Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. I'm running maven, spring, and mule.

When running a test maven build, the log4j2.xml file is not being picked up. 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).

Why would log4j pick up the log4j2-test.xml but not the log4j2.xml?

like image 665
Tanner Rutgers Avatar asked Aug 04 '15 02:08

Tanner Rutgers


People also ask

Where do I put log4j xml configuration file?

This logging system is configured by placing the log4j. xml file in the web application's WEB-INF/classes folder and by specifying the log output path for appenders and the level of logging.


1 Answers

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. Try finding the location of which conf file is getting pulled by having the following code execute when you run your maven test build:

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());
    }
}
like image 112
heenenee Avatar answered Oct 26 '22 02:10

heenenee