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.
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.
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
Thanks Ankur for the acrticle,
ReplyWhy we have 2 log files:
testlog.log
testlog1.log
Both are capturing same type of logs. Please shed some light.