Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable scalatest logging statements when running tests from maven

Tags:

scalatest

What is the method to disable logging on the scalatest log4j messages:

The log4j.properties is as follows:

log4j.rootLogger=INFO,CA,FA

#Console Appender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c: %m%n
log4j.appender.CA.Threshold = INFO


#File Appender
log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.append=false
log4j.appender.FA.file=target/unit-tests.log
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%d{HH:mm:ss.SSS} %p %c{1}: %m%n
log4j.appender.FA.Threshold = INFO

..
log4j.logger.org.scalatest=WARN

However we are seeing INFO level scalatest log4j messages:

2014-11-30 14:25:57,263 INFO  [ScalaTest-run-running-DiscoverySuite] Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(840)) - hadoop.native.lib is deprecated. Instead, use io.native.lib.available
2014-11-30 14:25:57,493 INFO  [ScalaTest-run-running-DiscoverySuite] hbase.HBaseCommonTestingUtility (HBaseTestingUtility.java:startMiniCluster(840)) - Starting up minicluster with 1 master(s) and 2 regionserver(s) and 2 datanode(s)
2014-11-30 14:25:57,499 INFO  [ScalaTest-run-running-DiscoverySuite] hbase.HBaseCommonTestingUtility (HBaseTestingUtility.java:setupClusterTestDir(390)) - Created new mini-cluster data directory: /shared/hwspark/target/
like image 798
WestCoastProjects Avatar asked Dec 01 '14 00:12

WestCoastProjects


3 Answers

Alternatively, you can throw this bit of code anywhere in one of your tests,

org.slf4j.LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME)
  .asInstanceOf[ch.qos.logback.classic.Logger]
  .setLevel(ch.qos.logback.classic.Level.WARN)

which will set all logging to the WARN level.

like image 181
Malcolm Avatar answered Nov 05 '22 03:11

Malcolm


Those log messages are not actually being printed by ScalaTest, but by something you are using from your ScalaTest tests. The reason "ScalaTest" shows up in them is that ScalaTest does change the name of threads when suites and tests are executed, so that if someone has a suite that hangs forever and does a thread dump to investigate, it is more obvious what test and suite is causing the run to hang. Log4J seems to print out the thread name in square brackets, so that can give you a hint as to where these log messages are coming from.

like image 37
Bill Venners Avatar answered Nov 05 '22 03:11

Bill Venners


In my case it was slick.relational I looked at the classpath with the class reported in ScalaTest-run-running-.... information and found the class to be find in a package imported and added that specific package to logback.xml as

<logger name="slick.relational" level="INFO"/>

In your case search for HBaseTestingUtility or the other class reported there to find which jar it contains it and work out your logback logger name from the package prefix.

like image 1
user2366514 Avatar answered Nov 05 '22 03:11

user2366514