Logging in Selenium
Logging in Selenium
Kus
LOG4J2 LOGGING IN
SELENIUM
Kushal Parikh
[email protected]
https://www.linkedin.com/in/kushalparikh11/
Kushal Parikh
QA Automation Engineer
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.23.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.23.1</version>
</dependency>
KUSHAL PARIKH 1
Kushal Parikh
QA Automation Engineer
To start logging messages using this basic configuration, all you need to
just obtain a Logger instance using the LogManager class:
Then you can use the logger object with methods corresponding to the log
level you want:
Note: Use this in the class you want to add log like base.class,
extentManager.class etc .
KUSHAL PARIKH 2
Kushal Parikh
QA Automation Engineer
Folder structure:
KUSHAL PARIKH 3
Kushal Parikh
QA Automation Engineer
Using Log4j2.properties
status = warn
name=PropertiesConfig
property.filename = logs
# Level of Logs
rootLogger.level = info
rootLogger.appenderRefs = file
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.logfile.ref = LOGFILE
rootLogger.appenderRef.htmlfile.ref = HTMLFILE
Using Log4j2.xml
KUSHAL PARIKH 5
Kushal Parikh
QA Automation Engineer
KUSHAL PARIKH 6