alexcuesta

My tech blog

Turning off HtmlUnit driver logging messages

leave a comment »

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>

Written by alexcuesta

May 11, 2011 at 4:56 pm

Posted in Java, Testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: