Log4j Architecture

In this tutorial we will see about log4j architecture. Already I mentioned there are two types of objects available in log4j in Log4J Introduction. We will see in detail now.

1.Core Objects – These are mandatory required object to use log4j framework

2.Support Objects – These are optional objects which give support to core object.

Log4J Core Objects

1.Logger

This is most important component of log4j.It is responsible for capture the logging information.Logger contains following levels.

Debug

Useful for debug an application

Info

Provides informational messages

Warn

Provide the details of harmful events

Error

It provide the error and exception thrown in application and allow the application continue its execution

Fatal

It provides the details severe error events like application may leads to abort

ALL

Used to turn on all logging level.

OFF

It is used to turn off all logging level

2. Appenders in log4

The Appender is responsible to publish log messages in desired destination. Log4j provides following appenders.

  1. Console Appender
  2. DailyRollingFileAppender
  3. FileAppender
  4. RollingFileAppender
  5. WriterAppender
  6. SMTPAppender
  7. WriterAppender
  8. SocketAppender
  9. SocketHubAppender
  10. SyslogAppender
  11. JDBCAppender
  12. TelnetAppender
  13. AppenderSkeleton
  14. AsyncAppender
  15. ExternallyRollingFileAppender
  16. JMSAppender
  17. LF5Appender
  18. NTEventLogAppender
  19. NullAppender

We will see the appenders in detail with examples.

3. Layouts in log4j

Layout is responsible for how to format layout.Types of log4j layouts are given below

1.HTMLLayout – It format output in table formatted output in html file.

2.PatternLayout – It format the output in given conversion pattern with all supported appenders

3.SimpleLayout – It provide simple formatted output. It output will be log level followed by log message

4.XMLLayout – Its provide the xml formatted output

Log4J Supported Objects

Level Objects

The level objects defines the priority to logging.Here I listed the levels in their priority

  1. ALL
  2. TRACE
  3. DEBUG
  4. INFO
  5. WARN
  6. ERROR
  7. FATAL
  8. OFF

We Will see these levels in details in upcoming chapters.

Log4J FILTER

Filter is object applied on logger and make further decision on whether information should be logged or not

Log4J ObjectsRenderer

The object renderer objects provides the string representation of different objects passed to log4j framework.this object used by layout to prepare final logging information

Log4J Logmanager

The LogManager is responsible for reading configuration information from confiuration file or class


Posts You may Like

  1. Java Best Practice – File Organization
  2. How to check hidden file or directory using Java
  3. Java Best Practice Reuse Objects instead of creating new ones if possible
  4. How to get Character unicode point in a String
  5. How to delete file using Java
  6. Java 7 Try statement with resources
  7. Java Tutorial – First Java Program
  8. Java 8 Convert a Stream to List
  9. How to retrieve all the files from Directory using Java File.listFiles()
  10. Read XML File as List of Object using SAX Parser
  11. How to change File Last modified Date using Java
  12. Create Pretty Print JSON using GSON
  13. How to make read-only file in Java
  14. First Java Application in Eclipse
  15. How to shuffle the element of collection (List)

Be the first to comment

Leave a Reply

Your email address will not be published.


*