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


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?


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.





In log4j2 you can write the following

org.apache.logging.log4j.LogManager ctx = (org.apache.logging.log4j.LogManager) LogManager.getContext(true);


Assuming log4j2-test.xml is in your classpath.



All Articles