What are different appenders that can configure in log4j?
There are 3 main components that are used to log messages based upon type and level.
These components help to log messages according to message type and priority. Also provide the formatting option.
These components are:
– loggers
– appenders
– layouts
Logger Object is responsible for storing the information which need to be logged
We need to create Logger Object in a class (one per class).
Example: static Logger log = Logger.getLogger(“your_class_name”);
Appender Objectis used to define the destination like file system, console, database, mail server etc. where user wants to save the log messages.
There are various appenders –
FileAppender –> used to write into a file. Files Appender is used to log the information into our custom name files. when we are configuring this appender, we can specify the file name
ConsoleAppender –> used to write into console. if we use this as appenders in your application, log4j logs the information in the console or command prompt window that is started with startup script.
JDBCAppender –> used to write in database
SMTPAppender –> used to send the log over mail
Again, in FileAppender we have 2 more
RollingFileAppenderwhich Rotates based on a maximum file size.
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org.apache.log4j.rolling.RollingFileAppender.
It has two important menthods –
setMaximumFileSize – Set the maximum size that the output file is allowed to reach before being rolled over to backup files.
setMaxBackupIndex – Set the maximum number of backup files to keep around.
More details about RollingFileAppender at:
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/RollingFileAppender.html
DailyRollingFileAppender which Rotates based on dateFormat.
DailyRollingFileAppender extends FileAppender so that the underlying file is rolled over at a user chosen frequency. DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss.
More details about DailyRollingFileAppender at:
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html
http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/DailyRollingFileAppender.html
Layout Object is responsible for layout and formating of the logging information to the desired format.
We have different type of layout classes in log4j
SimpleLayout
PatternLayout
HTMLLayout
XMLLayout