Log4j Layouts

The layout is responsible for formatting the logging request according to the user’s wishes. Layout can be set by attaching it with the appender.

In Log4j, there are following Layouts :

Layout Description
DateLayout This abstract layout takes care of all the date related options and formatting work.
EnhancedPatternLayout This layout is an enhanced version of org.apache.log4j.PatternLayout. This pattern layout should be used in preference to org.apache.log4j.PatternLayout except when compatibility where PatternLayout has been extended either through subclassing or alternative pattern parsers.

A flexible layout configurable with pattern string. The goal of this class is to format a LoggingEvent and return the results in a StringBuffer. The format of the result depends on the conversion pattern.
HTMLLayout This layout outputs events in a HTML table. Appenders using this layout should have their encoding set to UTF-8 or UTF-16, otherwise events containing non ASCII characters could result in corrupted log files.
PatternLayout A flexible layout configurable with pattern string. This code is known to have synchronization and other issues which are not present in org.apache.log4j.EnhancedPatternLayout.

The goal of this class is to format a LoggingEvent and return the results as a String. The results depend on the conversion pattern.
SimpleLayout SimpleLayout consists of the level of the log statement, followed by ” – ” and then the log message itself. For example,

DEBUG – Hello world
XMLLayout The output of the XMLLayout consists of a series of log4j:event elements as defined in the log4j.dtd. It does not output a complete well-formed XML file. The output is designed to be included as an external entity in a separate file to form a correct XML file.




,

No comments yet.

Leave a Reply