how to create log files in selenium webdriver using Log4J

Hello welcome to Selenium Tutorials, in this post we will see how to create log files in selenium

In Automation, reporting plays an important role so we can generate the different type of HTML reports, XSLT report, log files etc.

 

If you want to create enhanced report and with log attached to HTML report you can use extent report (I use this report) as well 

 

Here is the YouTube video for the same

 What is Log File?

The log file is a just simple file, which keeps track of the record or event or info when any event happens or any software run. This whole process is known as logging. We can create a log file as simple log file as well as HTML format.

Note- Any file whose extension is .log will be considered.

Sample Log file
1- Simple log file in text format

log file in Selenium

log file in Selenium

2- Log files in HTML format

how to create log files in selenium

how to create log files in selenium

Why is it required in Selenium?

We can create a log file for our simple script also so we can track or debug our script easily if anything goes wrong in the script. For example, if our script is failing at some point then we can track back what went wrong.

What is log4J
Log4j is free open source tool given by Apache foundation for creating log files It helps us to generate a log file in various output target.

How to create log files in selenium

Step 1- Download log4j jar file

Click on the link to download http://mirrors.ibiblio.org/pub/mirrors/maven/log4j/jars/log4j-1.2.15.jar

Step 2- Add log4j to your current project

Select your project > Right click > Click on build path> Click Configure build path> Go to library section > Add external jar file > select the log4j > click on save

Step 3- Open notepad and copy the below code and save the file as log4j.properties.

Note- Please create the log folder inside home directory and while saving use “” to save file

Once you save file it will look like

how to create log files in selenium

how to create log files in selenium

Step 4- Write test case

Step 5- Execute  your test case and verify the output and log files as well

Finally, here are three different log files.

how to create log files in selenium

how to create log files in selenium

 

 

 

 

 

 

 

53 Comments

  1. falak garg
  2. Nikhil
  3. Nirupa
  4. chandrika
  5. siva
  6. Nikhil
  7. Pratikshya
  8. Ajay Somni
  9. ganesh
  10. ganesh
  11. Sireesha
  12. Prasanna
  13. Ratna
  14. Siddharth
  15. pooja
  16. rahul
  17. Prabhakar Reddy Gollapudi
  18. Sandeep
  19. shubham
  20. yaswanth
  21. Rajiv
  22. Matt W
  23. AthenaTietjen9
  24. TyreeKeener28

Leave a Reply