Log4j introduction in Selenium – User friendly Tech help

What is Log4j?
nLog4j is a Java library,which is used in logging.  Log4j came into existence in 1996, as an initiative by SEMPER group to create a tracing API. Log4j is an open source tool and licensed under Apache Software License.

n

n

n

n

n

n

n

n

log4j

n

nAt its most basic level, we can imagine this as a replacement for System.out.println(sysout) statement in our code.But it is far more superior than sysout,but how? Let’s elaborate on this.
n
nWhy Log4j?
nLets discuss some advantages of log4j:-

n

    n

  • The output from Log4j can go to the console, to an email server, a database table, a log file, or numerous other destination, unlike sysout which outputs to standard output, which typically is a console window.
  • n

  • It allows different levels of logging like TRACE, DEBUG, INFO, WARN, ERROR, and FATAL. Say if we set a  particular log level, messages will get logged for that level and all levels above it, For instance, for log level = Error, we will have log messages that are errors and fatal and if we have log level = Info, we will have log messages that are info, warn, error, and fatal.
  • n

  • Log4j provides the feature to define the format of output logs. Furthermore we can configure Log4j via a configuration file, making it easy to control the logging behavior by editing this file, without touching the application binary.
  • n

n

nMain components of Log4j:-

n

LOGGER:
nLogger is responsible for handling the majority of log operations.This object of logger class is responsible for capturing logging information and Control over which logging statements are enabled or disabled.
n
nAPPENDER:
nAppender is responsible for controlling the output of log operations.This Appender object is responsible for publishing logging information to various preferred destinations such as a database, file, console, etc.
n
nSome example of appender:-

n

n

n

n

n

n

n

n

Appenders in log4j

nLAYOUT:
nLayout is responsible for formatting the output for Appender.
nLayout objects play an important role in publishing logging information in a way that is human-readable and reusable. The most popular layouts are the PatternLayout and HTMLLayout.n

Don’t worry will have working codes with more explanation about them.
n

Follow the below readings to learn more because “the best is yet to come…”:-
nDownloading log4j 
nFirst test case using Log4j
nUsing Configuration file in log4j

Was this article helpful?
YesNo

Similar Posts