0% found this document useful (0 votes)
331 views3 pages

Log4j Multiple Appenders - Tutorialspoint Examples

Java Log4j multiple appenders example. Let us discuss how to configure multiple file appenders in log4j with example. http://tutorialspointexamples.com/log4j-multiple-appenders-example/. See more at: http://tutorialspointexamples.com/log4j-tutorial-beginners-eclipse/

Uploaded by

Jai Pannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
331 views3 pages

Log4j Multiple Appenders - Tutorialspoint Examples

Java Log4j multiple appenders example. Let us discuss how to configure multiple file appenders in log4j with example. http://tutorialspointexamples.com/log4j-multiple-appenders-example/. See more at: http://tutorialspointexamples.com/log4j-tutorial-beginners-eclipse/

Uploaded by

Jai Pannu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1/3/2016

Log4jmultipleappenders|Tutorialspointexamples

Tutorialspointexamples
(http://tutorialspointexamples.com)
Learnjavatutorialwithexamplesforbeginnersonline
Search

Log4jMultipleAppendersExample
Letusdiscusstheuseofmultipleappenderswiththehelpofbelowexample.Inthisexampleweareusing
twoappendersCA(ConsoleAppender)andFA(FileAppender)withdifferentconfigurations.

Example:
Log4jTest.java
importorg.apache.log4j.Logger;

/**
*Thisclassisusedtoshowtheuseof
*multipleappenderswiththelog4j.propertiesfile.
*@authorjavawithease
*/
publicclassLog4jTest{

//GettheLoggerobject.

privatestaticLoggerlog=Logger.getLogger(Log4jTest.class);

publicstaticvoidmain(String[]args){

//loggermessages

log.debug("Log4jdebugmessagetest.");

log.info("Log4jinfomessagetest.");

log.warn("Log4jwarnmessagetest.");

log.error("Log4jerrormessagetest.");

log.fatal("Log4jfatalmessagetest.");

}
}

log4j.properties

http://tutorialspointexamples.com/log4jmultipleappendersexample/

1/6

1/3/2016

Log4jmultipleappenders|Tutorialspointexamples

#log4j.rootCategory=INFO,DEBUG,A1,LFS,FA,CA
log4j.rootLogger=DEBUG,CA,FA

#SetConsoleAppender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
#SetCALayout
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%m%n

#SetFileAppender
log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.File=test.log
#SetFALayout
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%m%n

#SetthelogginglevelofFAtoWARN
log4j.appender.FA.Threshold=WARN

Output:
Console
Log4jdebugmessagetest.
Log4jinfomessagetest.
Log4jwarnmessagetest.
Log4jerrormessagetest.
Log4jfatalmessagetest.

test.log
Log4jwarnmessagetest.
Log4jerrormessagetest.
Log4jfatalmessagetest.

Downloadthisexample.(http://tutorialspointexamples.com/wp
content/uploads/2014/09/Log4jExample4.rar)

PreviousTopic:Log4jfileappender.(http://tutorialspointexamples.com/log4jfileappender/)

RelatedTopics:
Howtobuildjavaprojectusingantineclipse?(http://tutorialspointexamples.com/howtobuildjava
projectusingantineclipse/)
JAXBmarshallingconvertjavaobjecttoxmlexample.(http://tutorialspointexamples.com/jaxb
marshallingconvertjavaobjecttoxmlexampleusingonepojo/)
HowtocreatepdffileinjavausingiTextjar?(http://tutorialspointexamples.com/howtocreatepdffile
injavausingitextjar/)
Genericsclassexample.(http://tutorialspointexamples.com/genericsclassexample/)
OGNLinstruts2.(http://tutorialspointexamples.com/ognlinstruts2/)
HibernateOnetoOneMappingusingxml.(http://tutorialspointexamples.com/hibernateonetoone

http://tutorialspointexamples.com/log4jmultipleappendersexample/

2/6

1/3/2016

Log4jmultipleappenders|Tutorialspointexamples

mappingusingxml/)
SendinlineimageinemailusingJavaMailAPI.(http://tutorialspointexamples.com/sendinlineimage
inemailusingjavamailapi/)
Quartz2JobListenerexample.(http://tutorialspointexamples.com/quartz2joblistenerexample/)

17

0
0

Share
Share

8
0

Share

Share

Log4j Tutorial
Log4joverview.(http://tutorialspointexamples.com/log4joverview/)
Loggerclass.(http://tutorialspointexamples.com/loggerclass/)
Log4jexample.(http://tutorialspointexamples.com/log4jexample/)
Log4jpropertiesfile.(http://tutorialspointexamples.com/log4jexampleusinglog4jpropertiesfile/)
Log4jxmlfile.(http://tutorialspointexamples.com/log4jexampleusinglog4jxmlfile/)
Logginglevels.(http://tutorialspointexamples.com/logginglevelsinlog4j/)
Log4jfileappender.(http://tutorialspointexamples.com/log4jfileappender/)
Log4jmultipleappenders.(http://tutorialspointexamples.com/log4jmultipleappendersexample/)

http://tutorialspointexamples.com/log4jmultipleappendersexample/

3/6

You might also like