Log4j2.xml and log4j2-test.xml in eclipse
I have these two log files in my eclipse classpath, in src/main/resources
and src/test/resources
respectively.
The problem is which log4j2-test.xml
is the higher priority and always the selected config file when my application starts. How do I tell eclipse to ignore log4j2-test.xml
and use log4j2.xml
when my application starts and fall back to log4j2-test.xml
when running unit tests?
+3
source to share
2 answers
In log4j2 you can write the following
org.apache.logging.log4j.LogManager ctx = (org.apache.logging.log4j.LogManager) LogManager.getContext(true);
ctx.setConfigLocation(LoggerTest.class.getClassLoader().getResource("log4j2-test.xml").toURI());
Assuming log4j2-test.xml is in your classpath.
-1
source to share