analytics

Sunday, April 17, 2011

Multiple Appenders Using XML File

Log4j XML Configuration


In this example we will see how to create more than one appender using xml configuration file. This example is similar to the one we saw before using the properties file (example). So I will simply compare both.


The following code shows the log4j.properties file we used in the previous example.

log4j.rootLogger=DEBUG, CA, FA

#Console Appender
log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
#File Appender
log4j.appender.FA=org.apache.log4j.FileAppender
log4j.appender.FA.File=sample.log
log4j.appender.FA.layout=org.apache.log4j.PatternLayout
log4j.appender.FA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
# Set the logger level of File Appender to WARN
log4j.appender.FA.Threshold = WARN

The following code shows the corresponding log4j.xml file.




















No comments:

Post a Comment