Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to disable log4j exception output during jUnit tests run?

Tags:

junit

maven

log4j

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.

like image 820
johnny-b-goode Avatar asked Jul 05 '12 13:07

johnny-b-goode


2 Answers

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.

like image 169
artbristol Avatar answered Sep 28 '22 11:09

artbristol


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);
like image 22
Cedric Reichenbach Avatar answered Sep 28 '22 10:09

Cedric Reichenbach