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


You can execute this below statement in the junit setup () method. This file must be avilable in the same package where you are doing this, or you can provide the full path for this file.



PropertyConfigurator.configure("log4j2-test.xml"); 

      

0


source


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







All Articles