I'm testing code that uses a third-party package (Kafka Streams), and this package is generating a lot of log statements that are cluttering up the test output. The log level goes all the way down to INFO. To make it easier to read the output I'd like to suppress all logging when running tests. Is this possible?
I'm using ScalaTest and log4j. I used sbt to build the project. I wasn't able to find anything about log suppression in the ScalaTest docs. Is the solution then to configure separate loggers, and use a logger configured for testing when testing? If so, how would I direct the third-party library to use this specific logger only when testing?
Here's some sample output, there's really no need for me to see these WARN or INFO statments:
- should filter invalid HelmData
Preprocessor.create_topology
[pool-1-thread-1-ScalaTest-running-EntityResolutionAppTest] WARN org.apache.kafka.streams.processor.internals.StateDirectory - Using an OS temp directory in the state.dir property can cause failures with writing the checkpoint file due to the fact that this directory can be cleared by the OS. Resolved state.dir: [/var/folders/mk/42jzsvb14jn_q5czv6cp6tcw0000gn/T//kafka-streams]
[pool-1-thread-1-ScalaTest-running-EntityResolutionAppTest] INFO org.apache.kafka.streams.state.internals.RocksDBTimestampedStore - Opening store helmDataByIdStateStore in regular mode
[pool-1-thread-1-ScalaTest-running-EntityResolutionAppTest] INFO org.apache.kafka.streams.state.internals.RocksDBTimestampedStore - Opening store KSTREAM-AGGREGATE-STATE-STORE-0000000014 in regular mode
[pool-1-thread-1-ScalaTest-running-EntityResolutionAppTest] INFO org.apache.kafka.streams.state.internals.RocksDBTimestampedStore - Opening store customerProfileStateStore in regular mode
[pool-1-thread-1-ScalaTest-running-EntityResolutionAppTest] INFO org.apache.kafka.streams.state.internals.RocksDBTimestampedStore - Opening store KSTREAM-AGGREGATE-STATE-STORE-0000000048 in regular mode
And here's what the output looks like when zoomed out, so you can get a sense of how cluttered it is:
The green text represents actual test results, and the red text is the log clutter.
I don't seem to be able to set log4j properties either. I have the following log4j.properties file in my project:
log = /tmp/log4j
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
But this doesn't seem to change logging behavior at all. If I understand correctly I should be seeing log statements written to a file, but that isn't happening.

Here you have all the log levels for log4j. Not sure which type of configuration you have. I mean, properties file, xml file, etc. You have to set the log level to
OFF. Here you have some examples on how to Enable/Disable Logging in log4j