Log4j API for creating logs in Selenium
Working with Log4J API
Log4j as this is an open source
logging library
Log4j is built with three main
concepts:
1.
loggers
2.
appenders
3.
Layouts.
Logger is the main engine which
sends the logging requests to appender. Appender might be a console, a
log file, printer, etc. Layout is the formatting of the log output.
Step 1) Include log4j jar in build path
2) Create log4j.properties in the src folder with below details
#Application Logs
log4j.logger.devpinoyLogger=DEBUG, dest1
log4j.appender.dest1=org.apache.log4j.RollingFileAppender
log4j.appender.dest1.maxFileSize=5000KB
log4j.appender.dest1.maxBackupIndex=3
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%d{dd/MM/yyyy HH:mm:ss} %c %m%n
log4j.appender.dest1.File=C:\\testing\\Application.log
#do not append the old file. Create a new log file everytime
log4j.appender.dest1.Append=false
3) Now do logging from any test case by using code like below
import org.apache.log4j.Logger;
public class Logging_Example {
/**
* @param args
*/
public static void main(String[] args) {
// add log4j.jar
// add log4j.propertie directly inside the src folder
// create the object in the code
Logger APPLICATION_LOGS = Logger.getLogger("devpinoyLogger");
APPLICATION_LOGS.debug("hello");
APPLICATION_LOGS.debug("We are wrinting in to a log file");
APPLICATION_LOGS.debug("starting the test case xyz test");
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment