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

一笑奈何 提交于 2020-01-03 16:58:13

问题


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);


来源:https://stackoverflow.com/questions/11344960/is-it-possible-to-disable-log4j-exception-output-during-junit-tests-run

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!