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?
Use LogManager. resetConfiguration(); to clear the current config and configure it again. Another approach is to build a new appender and replace the old one with it (most appenders don't support changing their config). This way, all the loggers (and their levels, etc) stay intact.
Log4j 2 doesn't support the Log4j v1 ". properties" format anymore (yet, since v2. 4, Log4j supports a Property format, but its syntax is totally different from v1 format). New formats are XML, JSON, and YAML, see the documentation (note: if you used one of these formats in a file called ".
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With