CustomLogger and Allure report

First we need to configure the class for log4j and report methods under the utilities package.

The methods under this class helps us to get the logs and report for test cases status whenever it is failed or Pass.

Now, Under the package utilities create a class as “Customlogger.py” and create two methods as customLogger and allureLogs.

We have created the reports folder and configured that in the customLogger method to save the reports and logs under it.


We have created a customized method allureLogs() to save the data in allure reports.

For more information on allure report click on the link.




CustomLogger.py

import inspect
import logging
import allure


def customLogger():
    # 1.) This is used to get the  class / method name from where this customLogger method is called
    logName = inspect.stack()[1][3]

    # 2.) Create the logging object and pass the logName in it
    logger = logging.getLogger(logName)

    # 3.) Set the Log level
    logger.setLevel(logging.DEBUG)

    # 4.) Create the fileHandler to save the logs in the file
    fileHandler = logging.FileHandler("../reports/Skill2lead.log", mode='a')

    # 5.) Set the logLevel for fileHandler
    fileHandler.setLevel(logging.DEBUG)

    # 6.) Create the formatter in which format do you like to save the logs
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s : %(message)s',
                                  datefmt='%d/%m/%y %I:%M:%S %p %A')

    # 7.) Set the formatter to fileHandler
    fileHandler.setFormatter(formatter)

    # 8.) Add file handler to logging
    logger.addHandler(fileHandler)

    #  9.) Finally return the logging object

    return logger


def allureLogs(text):
    with allure.step(text):
        pass



This will save the allure logs and customize log4j logs in the report folder under Selenium FrameWork.

Regarding allure report you can have a look in the generate allure report section.


Look into the below data how log4j test logs look like.

02/05/21 11:16:59 PM Sunday - WebDriverClass - INFO : Chrome Driver is initializing
02/05/21 11:17:09 PM Sunday - BaseClass - INFO : Web Page not Launched with URL : http://www.dummypoint.com/seleniumtemplate.html
02/05/21 11:17:09 PM Sunday - BaseClass - INFO : WebElement found with locator value Form using locatorType link
02/05/21 11:17:10 PM Sunday - BaseClass - INFO : Clicked on WebElement with locator value Form using locatorType link
02/05/21 11:17:10 PM Sunday - BaseClass - INFO : WebElement found with locator value reused_form using locatorType id
02/05/21 11:17:10 PM Sunday - BaseClass - INFO : WebElement is Displayed on web page with locator value reused_form using locatorType id
02/05/21 11:17:15 PM Sunday - BaseClass - INFO : WebElement found with locator value name using locatorType id
02/05/21 11:17:15 PM Sunday - BaseClass - INFO : Sent the text Code2Lead in WebElement with locator value name using locatorType id
02/05/21 11:17:15 PM Sunday - BaseClass - INFO : WebElement found with locator value email using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : Sent the text abc@gmail.com in WebElement with locator value email using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : WebElement found with locator value message using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : Sent the text This is a Code2Lead in WebElement with locator value message using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : WebElement found with locator value captcha_image using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : Got the text SGH456 from WebElement with locator value captcha_image using locatorType id
02/05/21 11:17:16 PM Sunday - BaseClass - INFO : WebElement found with locator value captcha using locatorType id