Log 4 J
Log 4 J
“Log4j is an Open Source. It is possible to store the flow details of our Selenium
Automation in a file. During the running of test case user wants some information to be logged
in the Console. Information could be any details depends upon the purpose. We need the
information which helps the User to understand the test steps or any failure during the test case
execution.”
Loggers
2. Define the log level: We can define the log levels in multiple forms and levels available
here: -
➢ Error: - It error events that might still allow the application to continue running.
Appenders
“In log4j, an output destination is called an appender. It allows the
destination where the logs would get saved. It supports the following types of appenders.”
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false">
<layout class="org.apache.log4j.PatternLayout">
</layout>
</appender>
<appender name="consoleAppender"
class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="INFO" />
<layout class="org.apache.log4j.PatternLayout">
</layout>
</appender>
<root>
</log4j:configuration>
4. Now Log4j.xml is created with code.
9. Now execute the code and print log in console and create new file name as logfile.log in
project (Refresh the project).