Log4j2.xml not found, but log4j2-test.xml

I am upgrading from log4j 1.x to log4j 2 and updated my log4j.xml config file to the new log4j2.xml config. I am running maven, spring and mule.

When running maven test build, the log4j2.xml file is not picked up. However, if I rename the log4j2-test.xml file, it is brought up (for example, the console logger with custom PatternLayout function works correctly in the second case, but in the first case the default configuration is used).

Why is log4j picking up log4j2-test.xml but not log4j2.xml?

+3


source to share


1 answer


Since it log4j2-test.xml

has a higher boot priority than log4j2.xml

, you probably have another log4j2 config file somewhere in your classpath that overrides yours log4j2.xml

. Try to find the location of the conf file you pulled out by executing the following code while running the 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());
    }
}

      

+3


source







All Articles