Turning off HtmlUnit driver logging messages
HtmlUnit was throwing lots of log messages while using cuke4duke (cucumber) to test our website from maven and I wanted to turn them off temporary but I struggled a bit. This is the solution I found on Stack Overflow:
I created the commons-logging.properties file under /src/main/resources and I specify that my logging framework is log4j (commons is just a wrapper):
# JDK Logging #org.apache.commons.logging.Log=org.apache.commons.logging.impl.Jdk14Logger # Log4j logging (also required log4j.jar to be in classpath) org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger
I created the log4j.xml file in the same folder /src/main/resources:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="out" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{yyyy-MM-dd, HH:mm:ss} %p - %m%n" />
</layout>
</appender>
<root>
<priority value="error" />
<appender-ref ref="out" />
</root>
</log4j:configuration>
and I added the missing dependency to log4j in the pom.xml file:
<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.12</version> </dependency>
Advertisement