Tuesday, August 14, 2012

LOG4J

1. Log4j simply inserts a log statement in the application code and manage them externally without going back to its application source code.
2. Programmer's can control the logging message with the help of external configuration file e.g. log4.xml or log4j.properties file.
3. The external properties file can be used to set the log format as well as the level of logging.
4. Three main component of Log4J are :-
        Logger
        Appender
        Layout
5. LOGGER:- It is responsible for capturing the logging information.
   There are few levels of logger:
        DEBUG : Most useful to debug an application.
        INFO  : It provides informational messages.
        WARN  : It provides that application may have harmful events.
        ERROR : It provides that application having error events but that might allow it to continue running.
        FATAL : It denotes the severe error events which lead the application to abort.
        ALL   : It is intended to turn on all logging.
        OFF   : It is intended to turn off all logging.
6. APPENDERS:- It is responsible for publishing the log to a destination. It controls how the logging provides the output.
   There are few list of appenders listed below:
        ConsoleAppender
        DailyRollingFileAppender
        FileAppender
        RollingFileAppender
        WriterAppender
        SMTPAppender
        SocketAppender
        SocketHubAppender
        SyslogAppendersends
        TelnetAppender
7. LAYOUT:- It is responsible for formatting the log output in different layouts. User can control the output format by modifying the Log4J configuration file.
   There are basically three types of Layout:
        HTMLLayout : It formats the output in the HTML table
        PatternLayout : It formats the output in the conversion pattern
        SimpleLayout : It formats the output in a simple manner, it prints the level then place a dash and then the user specified log message.
8. CONFIGURING LOG4J:- Put log4j.properties and log4j.xml in classpath i.e. directly under src folder of the application.
    Log4j looks for log4j.xml file first and then go for log4j.properties hence you must place both the files in your folder. We use log4j.xml since properties file does not provide some advanced configuration options such as Filter, some of ErrorHandlers, and few advanced Appenders.
  


No comments:

Post a Comment

SpringBoot Application Event Listeners

When a spring boot application starts few events occurs in below order ApplicationStartingEvent ApplicationEnvironmentPreparedEvent Applicat...