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?
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.
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());
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With