Trace and debug logs can be helpful while doing development in the IDE, but during the build I find those lines quite disturbing, and obfuscating the report printed out by maven or other build tools.
It would be nice to have log4j honoring a system property like -Dlog4j.rootLogger=OFF
1 to use with maven or something which doesn't require changes on the project files.
I know I can specify the -Dlog4j.configuration=alternateconfig.props
2 but I'm asking here to find out if somebody found a smarter way to disable logging during the build process with minimal manual intervention. I.e. some java class detecting maven as caller that disables log4j, or other smart solutions.
Any hint?
Notes:
[1]: already tried, and it doesnt work.
[2]: that's pretty good, but it doesn't seem to work well with maven (maybe surefire skips it)
As explained by
@artbristol
(comment on the question) this can be configured in surefire. It can be done in this way in the pom.xml:Then, having the file
${basedir}/etc/log4j-silent.properties
with following settings does the trick:The log4j gets completely disabled during test runs in maven, and everything works normally in the IDE.
A better solution would be not to have the additional configuration file; but can't find it so far.
Based on the previous answers, I use:
The Maven output shows a warning about log4j not being initialized, but other than that it seems to work.
Specify a test log4j configuration file with no appender.
For example if you have a log4j.properties in
src/main/resources
, then copy it tosrc/test/resouces
and either remove the appender or set the log level to fatal.