Easy learning with example program codes

Log4j multiple appenders example

Let us discuss the use of multiple appenders with the help of below example. In this example we are using two appenders CA(Console Appender) and FA(File Appender) with different configurations.


import org.apache.log4j.Logger;
 * This class is used to show the use of 
 * multiple appenders with the file.
 * @author codesjava
public class Log4jTest {
	//Get the Logger object.
	private static Logger log = Logger.getLogger(Log4jTest.class);
	public static void main(String[] args) {	
		//logger messages
		log.debug("Log4j debug message test.");"Log4j info message test.");
		log.warn("Log4j warn message test.");
		log.error("Log4j error message test.");
		log.fatal("Log4j fatal message test.");		

log4j.rootLogger=DEBUG, CA, FA
#Set Console Appender
#Set CA Layout
#Set File Appender
#Set FA Layout
#Set the logging level of FA to WARN
log4j.appender.FA.Threshold = WARN



Log4j debug message test.
Log4j info message test.
Log4j warn message test.
Log4j error message test.
Log4j fatal message test.


Log4j warn message test.
Log4j error message test.
Log4j fatal message test.

Download this example.
Previous Topic: Log4j file appender.

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki