How to override log4j.properties during testing?

2019-04-18 11:32发布

I'm trying to log all DEBUG messages to console during testing in maven. For this purpose I created a file src/test/resources/log4j.properties, which is going to override the configuration I already have in src/main/resources/log4j.properties. Unfortunately such an overriding is not happening. Why and how to fix it?

2条回答
【Aperson】
2楼-- · 2019-04-18 12:23

It should work as it is, and it works. The problem is somewhere else.

ps. I had a mess with loggers in my classpath: jog4j, slf4j, logback (from other dependencies). As I understand, all of them are in conflict. I didn't clean this mess yet, and I still don't know how to make all packages to use one logging facility and one configuration.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-04-18 12:34

Rename your test configuration file to e.g. log4j-surefire.properties and configure log4j to pick it up during surefire execution:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <systemPropertyVariables>
            <log4j.configuration>file:${project.build.testOutputDirectory}/log4j-surefire.properties</log4j.configuration>
        </systemPropertyVariables>
    </configuration>
</plugin>
查看更多
登录 后发表回答