RollingFileAppender

RollingFileAppender

The main intention of RollingFileAppender is to manage logging messages to the other new files when the present log file is getting exceeded as per the file size limit. If we want to use RollingFileAppender in log4j applications then we have to use “org.apache.log4j.RollingFileAppender” class and we have to use all the FileAppender properties and the following extra properties.

log4j.appender.Ref_Name.MaxFileSize = It will take max File size in the form of KB
log4j.appender.Ref_Name.MaxBackupIndex= It able to create maximum backup files.

E.g

log4j.properties

log4j.rootLogger = ALL, FILE

RollingFileAppender Configuration

log4j.appender.FILE = org.apache.log4j.RollingFileAppender
log4j.appender.FILE.file= /home/ashok/loggers/ashok.txt
log4j.appender.FILE.MaxFileSize= 5MB
log4j.appender.FILE.MaxBackupIndex= 3
log4j.appender.FILE.layout = org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern = %d{yyyy-mm-dd hh:mm:ss } %-c %p : This is %m%n
package com.ashok.log4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 * 
 * @author ashok.mariyala
 *
 */
public class TestLog4J {
	private static final Logger LOG = LoggerFactory.getLogger(TestLog4J.class);
	public static void main(String[] args) {
		LOG.trace("This is trace message"); 
		LOG.debug("This is debug message");
		LOG.info("This is info message"); 
		LOG.warn("This is warn message"); 
		LOG.error("This is error message"); 
	}
}
RollingFileAppender
Scroll to top