Thursday, May 31, 2012

Log4j using XML configuration.

Please follow the following program to understand log4j implementation using xml file.
Here I have used console appender to log the events.

Java : XMLConfigurationDemo
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class XMLConfigurationDemo {

      private static final Logger logger = Logger.getLogger(XMLConfigurationDemo.class);

      public static void main(String[] args) {
            logger.trace("Trace Message.");// Point to Point.
            logger.debug("Debug Message.");// Method to Method.
<xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j=''>
      <appender name="Console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                  <param name="ConversionPattern" value="%p %c - %m%n" />
            <level value="trace" />
            <appender-ref ref="Console" />

No comments:

Post a Comment