4

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
Biscuit128
  • 5,218
  • 22
  • 89
  • 149
  • What output? Your applications logs or JUnit's logs? If JUnit, disable the appropriate logger (log4j.logger.org.junit=OFF) – John B Aug 07 '14 at 12:57
  • i am getting the output of junit tests in my application logs – Biscuit128 Aug 07 '14 at 12:58
  • Again, what do you mean "output of junit tests"? Are these logs from JUnit code or from your application's code that is being invoked by your tests? – John B Aug 07 '14 at 13:00
  • these are log statements produced by my application code as the methods were invoked by my tests – Biscuit128 Aug 07 '14 at 13:01

1 Answers1

5

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.

Community
  • 1
  • 1
Raedwald
  • 46,613
  • 43
  • 151
  • 237