Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop JUNit from Logging

I am using Junit as my testing technology. Along with this I am also using log4j to log from my main application.

I am encountering an issue where, when Jenkins runs my test cases it is logging the output to my applications log file which is less than ideal.

Is it possible to suppress these log messages some how? My log4j properties is as follows;

log=/var/opt/jboss/standalone/log/myapp.log
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
log4j.rootLogger=DEBUG, FILE

log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.append=true
log4j.appender.FILE.file=${log}
log4j.appender.FILE.threshold=DEBUG
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d %-5p %c - %m%n
like image 632
Biscuit128 Avatar asked Sep 03 '25 03:09

Biscuit128


1 Answers

You can do this by having a custom log4j.properties file that you use only for testing, have that configuration tell log4j not to produce any logging, and place the custom properties file in a location that will cause it to be used during runs of your unit tests (and only those runs), by having it in a preferred directory in your classpath used for testing. If you are using Maven and/or eclipse, you would put your custom properties file in the directory src/test/resources.

like image 80
Raedwald Avatar answered Sep 05 '25 19:09

Raedwald