Showing posts with label Apache Log4j. Show all posts
Showing posts with label Apache Log4j. Show all posts

Thursday, May 28, 2015

How to setup Logging for Selenium web driver script

1. Open http://logging.apache.org/

2. Open Apache log4j link

3. Download from left shoulder tab

4. Extract and add Log4j Jar to eclipse

5. Create log4j.xml in the root folder of the script

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

<appender name="fileAppender" class="org.apache.log4j.FileAppender">

<param name="Threshold" value="INFO" />

<param name="File" value="logfile.log"/>

<layout class="org.apache.log4j.PatternLayout">

<param name="ConversionPattern" value="%d %-5p [%c{1}] %m %n" />

</layout>

</appender>

<root>

<level value="INFO"/>

<appender-ref ref="fileAppender"/>

</root>

</log4j:configuration>

6. Use Log.info("New driver instantiated"); comments across your scripting

7. Import following packages into the script

import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

8. Update below code under class file
private static Logger Log = Logger.getLogger(MLPTweets.class.getName());

9. With main section set the log file config

DOMConfigurator.configure("log4j.xml");

10. Where ever log needed update the following command in Log.Info();

Log.info("Tweets Data file Opened");

11. After the execution, open the logfile.log from the base folder and verify