Is it possible to disable log4j exception output d

2019-06-26 05:48发布

问题:

Need to disable log4j output to console during jUnit tests running but all other log4j output should be enable. There are lot exceptions during testing while checking method reaction on incorrect argument, so exception is ok.

回答1:

Create a new log4j properties file called e.g. log4j-test.properties with logging disabled. In your surefire config in the POM, add argLine with -Dlog4j.configuration=log4j-test.properties.



回答2:

I know this question is quite old, but still relevant in my opinion, so I'll add an alternative answer.

If you just want to disable (or reduce) logging for certain tests, or for some reason want to do it from code rather than creating a config file, you could do the following:

RootLogger.getRootLogger().setLevel(Level.OFF);