log4j in RestAssured Testing Framework



 log4j in RestAssured Testing Framework


log4j is a reliable, fast and flexible logging framework (APIs) written in Java, which is distributed under the Apache Software License.

log4j has been ported to the C, C++, C#, Perl, Python, Ruby, and Eiffel languages.


log4j is highly configurable through external configuration files at run time and it is basically used to write our own logs inside the code so it would be easy to troubleshoot code in case of any issue.



Now we need to follow the below steps to setup Log4j in rest assured testing framework.
1) In Project Folder inside pom.xml add below log4j dependencies.


2) Inside project main Folder under configuration or any other Package of choice please add below log4j.properties file with the below details.        


3) Inside project Base Class, declare one logger variable and provide the path of log4j.properties file along with the below code snapshot.

 4)  Now we are ready to use your log4j inside test classes using the below syntax.       



logger.info("Issue Created with id \t"+IssueNo);

       log4j can primarily be added on below level:

·      All - This level of logging will log everything ( it turns all the logs on )
·      DEBUG – print the debugging information and is helpful in development stage
·      INFO – the print informational message that highlights the progress of the application
·      WARN – print information regarding faulty and unexpected system behavior.
·      ERROR – the print error message that might allow the system to continue.
·      FATAL – print system critical information which is causing the application to crash


 After executing the Code output would look something like below in console.




Now after refreshing our the project, we will get one new folder created with name as log inside this folder there would be file name as testlog.log inside this file we will get all the loggers we have written inside the project.



Please refer this blog to know more about Request and Response Logging in Rest Assured Framework

You may also be interested to know How to Read Data from Properties File


Keep Learning, Keep Sharing J



SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
August 14, 2019 at 8:02 PM

Thanks Ankur for the acrticle,

Why we have 2 log files:

testlog.log
testlog1.log

Both are capturing same type of logs. Please shed some light.

Reply
avatar