I have these two log files on my eclipse classpath, in src/main/resources
and src/test/resources
respectively.
我在eclipse类路径上分别在src / main / resources和src / test / resources中有这两个日志文件。
The problem is that log4j2-test.xml
is higher priority and is always the chosen configuration file when running my application. How do I tell eclipse to ignore log4j2-test.xml
and use log4j2.xml
when running my application and to fall back to log4j2-test.xml
when running unit tests?
问题是log4j2-test.xml具有更高的优先级,并且在运行我的应用程序时始终是所选的配置文件。如何在运行我的应用程序时告诉eclipse忽略log4j2-test.xml并使用log4j2.xml,并在运行单元测试时回退到log4j2-test.xml?
2 个解决方案
#1
0
You can execute this below statement in junit setup() method.This file should be avilable in the same package where your running this or you can provide the full path for this file.
您可以在junit setup()方法中执行以下语句。此文件应该在您运行此文件的同一个包中提供,或者您可以提供此文件的完整路径。
PropertyConfigurator.configure("log4j2-test.xml");
#2
-1
In log4j2 you can write the following
在log4j2中,您可以编写以下内容
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.
假设log4j2-test.xml在您的类路径中。
#1
0
You can execute this below statement in junit setup() method.This file should be avilable in the same package where your running this or you can provide the full path for this file.
您可以在junit setup()方法中执行以下语句。此文件应该在您运行此文件的同一个包中提供,或者您可以提供此文件的完整路径。
PropertyConfigurator.configure("log4j2-test.xml");
#2
-1
In log4j2 you can write the following
在log4j2中,您可以编写以下内容
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.
假设log4j2-test.xml在您的类路径中。