Combine TestNGListener with log4j for selenium result reporting

This post will explain the integration of any java logger (let’s say Log4j) with ITestListener to customise result output and print the same to log file.

We have seen testNG and it’s listener ITestListener to customise the result output.


Watch details here

Log4j maven dependency

Use below dependency –

Log4j properties file

Create a new folder “resources” under “src > main” folder, and create a new file under src > main > resources with below content


Project folder structure

Implement ITestListener interface

Create a package “testNGListener.Logger”, and then create

Create a common Log class


Test class or Test case



Run testng.xml, a folder “Log4j” will be created under current project with application.log file



For more info on log4j, you can refer

Content posted is based on learning or working experience,
Share the post with others if find useful,
Any queries?, leave comments or discuss on our, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *