Log4J2 | Logging in Java framework | Selenium test automation

preview_player
Показать описание
In this video we will discus about logging in automation framework. There are many number of logging libraries available, which can be use in our framework. But in our framework we are going to use Apache Log4j2.

Different Log events we can use in Log4j2are as below:
ERROR
WARN
INFO
DEBUG
VERBOSE

dependency
artifactId log4j-core /artifactId
version 2.13.3 /version
/dependency

To initialize the logger in class you can write the below code.

Then you can use the log object to generate logs.

Based on the minimum log event type, provided in the configuration we will get the log events in the log file.

#?xml version="1.0" encoding="UTF-8"?#
#Configuration status="WARN" strict="true"#
#Properties#
#/Properties#
#Appenders#
#Appender type="Console" name="STDOUT" #
#Layout type="PatternLayout" pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/#

#/Appender#
#Appender type="File" name="File" fileName="${filename}"#
#Layout type="PatternLayout" pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/#

#/Appender#
#/Appenders#

#Loggers#

#Root level="info"#
#AppenderRef ref="File"/#
#/Root#
#/Loggers#

#/Configuration#

Please comment in case of any queries.

Also please see my other videos as well.

Рекомендации по теме
Комментарии
Автор

bhaiya aap insaan nai bhagwan hai mere liye...mera ab ja ke kaam hua...itne sare videos dekhe but kisi ne ye btaya hi nai tha ki root level me save karna tha file....and thanks for the xml file, ,woring fine for all latest dependencies,
Thanks a lot...🥰

IndianVistas
Автор

does the log4j2.xml file gets generated automatically after adding the dependency?

rohitdesurkar
Автор

How to send an email when error occurs i have added SMTP appender how to add Root level. please check my Root levels, is this correct to specify only error has to been mailed
<Root >
<AppenderRef ref="Console" level="info"/>
<AppenderRef ref="RollingFile"level="info" />
<AppenderRef ref="LogToMail" level="error"/>
</Root>

spnarayanrao