Thursday, July 30, 2020

How to add logger log4j in Selenium Test?

1. Add below dependency in pom.xml file:

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
You can find the latest dependency from Apache Maven repo

2. Create log4j.properties file and add below content:

log4j.rootLogger=INFO, FA, stdout
#File Appender
log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.File=log/AppLog.log
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%-4r [%t] %-5p %d{dd MMM yyyy HH:mm:ss} %c %x - %m%n

#Log to Console as STDOUT
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c %3x - %m%n

#Log to file FILE
#log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=logfile.log
#log4j.appender.file.DatePattern='.'yyyy-MM-dd
#log4j.appender.file.append=true
#log4j.appender.file.layout=org.apache.log4j.PatternLayout
#log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c %3x - %m%n

3. Setup and configure log4j property file in java class:

PropertyConfigurator.configure("YOUR_LOG4J_PROPERTY_FILEPATH");



No comments:

Post a Comment

Read CSV from S3

 import csv def count_records(csv_file):     record_count = 0     first_line = None     last_line = None     # Open the CSV file and read it...