logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject cvs commit: jakarta-log4j/src/java/org/apache/log4j/pattern LineSeparatorPatternConverter.java PatternParser.java
Date Thu, 18 Sep 2003 21:26:55 GMT
ceki        2003/09/18 14:26:55

  Modified:    tests/src/java/org/apache/log4j PatternLayoutTest.java
               examples/jmx T.java
               src/java/org/apache/log4j FileAppender.java
                        PatternLayout.java
               .        build.xml
               tests/input patternLayout14.properties
               examples/customLevel XLevel.java
               examples/subclass MyLogger.java MyLoggerFactory.java
                        MyLoggerTest.java
               tests    build.xml
               src/java/org/apache/log4j/pattern PatternParser.java
  Added:       examples/sort sort4.properties Sort.java sort2.properties
                        sort1.properties sort3.properties SortAlgo.java
               examples/pattern CountingPatternConverter.java
                        MyPatternLayout.java
               tests/src/java/org/apache/log4j/pattern
                        Num343PatternConverter.java PatternParserTest.java
               examples/subclass mycat.bad mycat.good
               examples/trivial Trivial.java
               examples/factor NumberCruncher.java
                        NumberCruncherClient.java NumberCruncherServer.java
                        factor.html factor.lcf
               tests/witness patternLayout.mdc.2
               src/java/org/apache/log4j/pattern
                        LineSeparatorPatternConverter.java
  Removed:     examples NumberCruncher.java sort1.properties Trivial.java
                        MyPatternLayout.java NumberCruncherClient.java
                        NumberCruncherServer.java Sort.java factor.html
                        mycat.bad MyPatternParser.java SortAlgo.java
                        factor.lcf sort2.properties sort3.properties
                        sort4.properties mycat.good
               tests/src/java/org/apache/log4j MyPatternLayout.java
                        MyPatternParser.java
               tests/witness PatternParser_mdc
               tests/src/java/org/apache/log4j/helpers
                        PatternParserTestCase.java
  Log:
  
  
  - Reaarangement of files under the examples/ directory.
  
  - PatternLayout can now easily deal with new conversion words. 
    Added test cases in relation to this enhancement. More tests to follow.
  
  - Changed MyPatternLayout under examples to take advantage of the
  new PatternLayout architecture. Notice how easy it is to add a new 
  conversion word.
  
  Revision  Changes    Path
  1.1                  jakarta-log4j/examples/sort/sort4.properties
  
  Index: sort4.properties
  ===================================================================
  # Attach appender A1 to root. Set root level to Level.DEBUG.
  log4j.rootLogger=DEBUG, A1
  
  # A1 is set to be a FileAppender sending its output to
  # System.out. However, only error messages and above will be printed
  # in A1 because A1's threshold is set to Level.ERROR.
  
  # The fact that the root level is set to Prority.DEBUG only influences
  # log requests made to the root logger. It has no influence on the
  # *appenders* attached to root.
  
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  log4j.appender.A1.Threshold=ERROR
  
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%p [%t] %c{2} (%M:%L) - %m%n
  
  # Set the level of the logger named "org.apache.log4j.examples" to 
  # Level.INFO, attach appender A2.
  log4j.logger.org.apache.log4j.examples=INFO, A2
  
  # Appender A2 writes to the file "test" in user's home.
  log4j.appender.A2=org.apache.log4j.FileAppender
  log4j.appender.A2.File=${user.home}/test
  
  # Truncate 'test' if it aleady exists.
  log4j.appender.A2.Append=false
  
  # Appender A2 uses the PatternLayout.
  log4j.appender.A2.layout=org.apache.log4j.PatternLayout
  log4j.appender.A2.layout.ConversionPattern=%5r %-5p [%t] %c{2} - %m%n
  
  
  
  1.1                  jakarta-log4j/examples/sort/Sort.java
  
  Index: Sort.java
  ===================================================================
  
  package sort;
  
  import org.apache.log4j.PropertyConfigurator;
  import org.apache.log4j.Logger;
  
  /**
     Example code for log4j to viewed in conjunction with the {@link
     examples.SortAlgo SortAlgo} class.
     
     <p>This program expects a configuration file name as its first
     argument, and the size of the array to sort as the second and last
     argument. See its <b><a href="doc-files/Sort.java">source
     code</a></b> for more details.
  
     <p>Play around with different values in the configuration file and
     watch the changing behavior.
  
     <p>Example configuration files can be found in <a
     href="doc-files/sort1.properties">sort1.properties</a>, <a
     href="doc-files/sort2.properties">sort2.properties</a>, <a
     href="doc-files/sort3.properties">sort3.properties</a> and <a
     href="doc-files/sort4.properties">sort4.properties</a> are supplied with the
     package.
     
     <p>If you are also interested in logging performance, then have
     look at the {@link org.apache.log4j.performance.Logging} class.
  
     @author Ceki G&uuml;lc&uuml; */
  
  public class Sort {
  
    static Logger logger = Logger.getLogger(Sort.class.getName());
    
    public static void main(String[] args) {
      if(args.length != 2) {
        usage("Incorrect number of parameters.");
      }
      int arraySize = -1;
      try {
        arraySize = Integer.valueOf(args[1]).intValue();
        if(arraySize <= 0) 
  	usage("Negative array size.");
      }
      catch(java.lang.NumberFormatException e) {
        usage("Could not number format ["+args[1]+"].");
      }
  
      PropertyConfigurator.configure(args[0]);
  
      int[] intArray = new int[arraySize];
  
      logger.info("Populating an array of " + arraySize + " elements in" +
  	     " reverse order.");
      for(int i = arraySize -1 ; i >= 0; i--) {
        intArray[i] = arraySize - i - 1;
      }
  
      SortAlgo sa1 = new SortAlgo(intArray);
      sa1.bubbleSort();
      sa1.dump();
  
      // We intentionally initilize sa2 with null.
      SortAlgo sa2 = new SortAlgo(null);
      logger.info("The next log statement should be an error message.");
      sa2.dump();  
      logger.info("Exiting main method.");    
    }
    
    static
    void usage(String errMsg) {
      System.err.println(errMsg);
      System.err.println("\nUsage: java org.apache.examples.Sort " +
  		       "configFile ARRAY_SIZE\n"+
        "where  configFile is a configuration file\n"+
        "      ARRAY_SIZE is a positive integer.\n");
      System.exit(1);
    }
  }
  
  
  
  1.1                  jakarta-log4j/examples/sort/sort2.properties
  
  Index: sort2.properties
  ===================================================================
  # An example log4j configuration file that outputs both to System.out
  # and a file named 'test'.
  
  # For the general syntax of property based configuration files see the
  # documenation of org.apache.log4j.PropertyConfigurator.
  
  # WARNING: Location information can be useful but is very costly in
  # terms of computation.
  
  # The root logger uses the appender called A1. 
  
  # The root logger uses the appenders called A1 and A2. Since no level
  # is specified, note the empty string between the comma (",") and the
  # equals sign ("="), the level of the root logger remains
  # untouched. Log4j always initializes the level for the root logger to
  # DEBUG. The root logger is the only logger that has a default
  # level. Bu default, all other loggers do not have an assigned level,
  # such that they inherit their level instead.
  
  log4j.rootLogger=, A1, A2
  
  # A1 is set to be ConsoleAppender sending its output to System.out
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  
  
  # A1 uses PatternLayout.
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  
  # The conversion pattern consists of date in ISO8601 format, level,
  # thread name, logger name truncated to its rightmost two components
  # and left justified to 17 characters, location information consisting
  # of file name (padded to 13 characters) and line number, nested
  # diagnostic context, the and the application supplied message
  
  log4j.appender.A1.layout.ConversionPattern=%d %-5p [%t] %-17c{2} (%13F:%L) %3x - %m%n
  
  # Appender A2 writes to the file "test".
  log4j.appender.A2=org.apache.log4j.FileAppender
  log4j.appender.A2.File=test
  
  # Truncate 'test' if it aleady exists.
  log4j.appender.A2.Append=false
  
  # Appender A2 uses the PatternLayout.
  log4j.appender.A2.layout=org.apache.log4j.PatternLayout
  log4j.appender.A2.layout.ConversionPattern=%-5r %-5p [%t] %c{2} - %m%n
  
  
  # In this example, we are not interested in INNER loop or SWAP
  # messages.  You might try to set INNER and SWAP to DEBUG for more
  # verbose output.
  
  log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=INFO
  log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=INFO
  
  
  
  1.1                  jakarta-log4j/examples/sort/sort1.properties
  
  Index: sort1.properties
  ===================================================================
  # An example log4j configuration file that outputs to System.out.  The
  # output information consists of relative time, log level, thread
  # name, logger name, nested diagnostic context and the message in that
  # order.
  
  # For the general syntax of property based configuration files see the
  # documenation of org.apache.log4j.PropertyConfigurator.
  
  log4j.rootLogger=DEBUG, A1
  
  # A1 is set to be a ConsoleAppender which outputs to System.out. 
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  
  # A1 uses PatternLayout.
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  
  # The conversion pattern uses format specifiers. You might want to
  # change the pattern an watch the output format change.
  log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n
  
  # In this example, we are not really interested in INNER loop or SWAP
  # messages. See the effects of uncommenting and changing the levels of
  # the following loggers.
  # log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=WARN
  # log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=WARN
   
  
  
  1.1                  jakarta-log4j/examples/sort/sort3.properties
  
  Index: sort3.properties
  ===================================================================
  # An example log4j configuration file that directs its logging output
  # to a SocketAppender. The SocketAppender is configuted to send its
  # output to a server running on the localhost port number 12345.
  
  # To test this example, you must start a log4j server with the command
  #
  #
  #  java org.apache.log4j.net.SocketServer 12345 configurationFile directory/
  #
  #
  
  # For the general syntax of property based configuration files see
  # the documenation of org.apache.log4j.PropertyConfigurator.
  
  # The root logger uses the appender called A1. 
  
  log4j.rootLogger=DEBUG, A1
  
  # A1 is set to be a SocketAppender sending its output to the server
  running on the local host, port 12345.
  
  log4j.appender.A1=org.apache.log4j.net.SocketAppender
  log4j.appender.A1.Port=12345
  log4j.appender.A1.RemoteHost=localhost
  
  # In this example, we are not interested in INNER loop or SWAP
  # messages.  You might try to set INNER and SWAP to DEBUG for more
  # verbose output.
  
  log4j.logger.org.apache.log4j.examples.SortAlgo.INNER=INFO
  log4j.logger.org.apache.log4j.examples.SortAlgo.SWAP=INFO
  
  
  
  1.1                  jakarta-log4j/examples/sort/SortAlgo.java
  
  Index: SortAlgo.java
  ===================================================================
  
  package sort;
  
  import org.apache.log4j.Category;
  import org.apache.log4j.NDC;
  
  /**
     Example code for log4j to viewed in conjunction with the {@link
     examples.Sort Sort} class.
        
     <p>SortAlgo uses the bubble sort algorithm to sort an integer
     array. See also its <b><a href="doc-files/SortAlgo.java">source
     code</a></b>.
  
     @author Ceki G&uuml;lc&uuml; */
  public class SortAlgo {
  
    final static String className = SortAlgo.class.getName();
    final static Category CAT = Category.getInstance(className);
    final static Category OUTER = Category.getInstance(className + ".OUTER");
    final static Category INNER = Category.getInstance(className + ".INNER");
    final static Category DUMP = Category.getInstance(className + ".DUMP");
    final static Category SWAP = Category.getInstance(className + ".SWAP");
  
    int[] intArray;
  
    SortAlgo(int[] intArray) {
      this.intArray = intArray;
    }
      
    void bubbleSort() {
      CAT.info( "Entered the sort method.");
  
      for(int i = intArray.length -1; i >= 0  ; i--) {
        NDC.push("i=" + i);
        OUTER.debug("in outer loop.");
        for(int j = 0; j < i; j++) {
  	NDC.push("j=" + j);
  	// It is poor practice to ship code with log staments in tight loops.
  	// We do it anyway in this example.
  	INNER.debug( "in inner loop.");
           if(intArray[j] > intArray[j+1])
  	   swap(j, j+1);
  	NDC.pop();
        }
        NDC.pop();
      }
    }  
  
    void dump() {    
      if(! (this.intArray instanceof int[])) {
        DUMP.error("Tried to dump an uninitialized array.");
        return;
      }
      DUMP.info("Dump of integer array:");
      for(int i = 0; i < this.intArray.length; i++) {
        DUMP.info("Element [" + i + "]=" + this.intArray[i]);
      }    
    }
  
    void swap(int l, int r) {
      // It is poor practice to ship code with log staments in tight
      // loops or code called potentially millions of times.
      SWAP.debug( "Swapping intArray["+l+"]=" + intArray[l] +
  	                     " and intArray["+r+"]=" + intArray[r]);
      int temp = this.intArray[l];
      this.intArray[l] = this.intArray[r];
      this.intArray[r] = temp;
    }
  }
  
  
  
  
  1.1                  jakarta-log4j/examples/pattern/CountingPatternConverter.java
  
  Index: CountingPatternConverter.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package pattern;
  
  import org.apache.log4j.pattern.PatternConverter;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  public class CountingPatternConverter extends PatternConverter {
    StringBuffer buf;
    int counter = 0;
  
    public CountingPatternConverter() {
      super();
      this.buf = new StringBuffer(5);
    }
  
    public StringBuffer convert(LoggingEvent event) {
      buf.setLength(0);
  
      return buf.append(String.valueOf(++counter));
    }
  }
  
  
  
  1.1                  jakarta-log4j/examples/pattern/MyPatternLayout.java
  
  Index: MyPatternLayout.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package pattern;
  
  import org.apache.log4j.ConsoleAppender;
  import org.apache.log4j.PatternLayout;
  import org.apache.log4j.Logger;
  import org.apache.log4j.Layout;
  
  /**
   * 
   * Example showing how to extend PatternLayout to recognize additional 
   * conversion characters.
   * 
   * <p>In this case MyPatternLayout recognizes %# conversion pattern. It outputs
   *  the value of an internal counter which is also incremented at each call.
   * 
   * @see org.apache.log4j.PatternLayout
   * @author Anders Kristensen
   * @author Ceki G&uuml;lc&uuml;
   */
  
  public class MyPatternLayout extends PatternLayout {
    public MyPatternLayout() {
      super();
    }
  
    public MyPatternLayout(String pattern) {
      super(pattern);
    }
  
    /**
      Activates the conversion pattern. Do not forget to call this method after
      you change the parameters of the PatternLayout instance.
    */
    public void activateOptions() {
      this.addConversionRule("#", CountingPatternConverter.class.getName());
      super.activateOptions();
    }
  
    public static void main(String[] args) {
      Layout layout = new MyPatternLayout("[counter=%.10#] - %m%n");
      Logger logger = Logger.getLogger("some.cat");
      logger.addAppender(new ConsoleAppender(layout, ConsoleAppender.SYSTEM_OUT));
      logger.debug("Hello, log");
      logger.info("Hello again...");
    }
  }
  
  
  
  1.3       +79 -2     jakarta-log4j/tests/src/java/org/apache/log4j/PatternLayoutTest.java
  
  Index: PatternLayoutTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/PatternLayoutTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PatternLayoutTest.java	17 Sep 2003 16:03:02 -0000	1.2
  +++ PatternLayoutTest.java	18 Sep 2003 21:26:55 -0000	1.3
  @@ -336,7 +336,7 @@
       assertTrue(Compare.compare(FILTERED, "witness/patternLayout.14"));
     }
   
  -  public void testMDCAllowAllKeys() throws Exception {
  +  public void testMDC1() throws Exception {
       PropertyConfigurator.configure("input/patternLayout.mdc.1.properties");
       MDC.put("key1", "va11");
       MDC.put("key2", "va12");
  @@ -378,6 +378,82 @@
       logger.log(Level.FATAL, "Message " + ++i, e);
     }
   
  +  /**
  +    Test case for MDC conversion pattern. */
  +  public void testMDC2() throws Exception {
  +    String OUTPUT_FILE   = "output/patternLayout.mdc.2";
  +    String WITNESS_FILE  = "witness/patternLayout.mdc.2";
  +    
  +    String mdcMsgPattern1 = "%m : %X%n";
  +    String mdcMsgPattern2 = "%m : %X{key1}%n";
  +    String mdcMsgPattern3 = "%m : %X{key2}%n";
  +    String mdcMsgPattern4 = "%m : %X{key3}%n";
  +    String mdcMsgPattern5 = "%m : %X{key1},%X{key2},%X{key3}%n";
  +    
  +    // set up appender
  +    PatternLayout layout = new PatternLayout("%m%n");
  +    Appender appender = new FileAppender(layout, OUTPUT_FILE, false);
  +            
  +    // set appender on root and set level to debug
  +    root.addAppender(appender);
  +    root.setLevel(Level.DEBUG);
  +    
  +    // output starting message
  +    root.debug("starting mdc pattern test");
  + 
  +    layout.setConversionPattern(mdcMsgPattern1);
  +    layout.activateOptions();
  +    root.debug("empty mdc, no key specified in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern2);
  +    layout.activateOptions();
  +    root.debug("empty mdc, key1 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern3);
  +    layout.activateOptions();
  +    root.debug("empty mdc, key2 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern4);
  +    layout.activateOptions();
  +    root.debug("empty mdc, key3 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern5);
  +    layout.activateOptions();
  +    root.debug("empty mdc, key1, key2, and key3 in pattern");
  +
  +    MDC.put("key1", "value1");
  +    MDC.put("key2", "value2");
  +
  +    layout.setConversionPattern(mdcMsgPattern1);
  +    layout.activateOptions();
  +    root.debug("filled mdc, no key specified in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern2);
  +    layout.activateOptions();
  +    root.debug("filled mdc, key1 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern3);
  +    layout.activateOptions();
  +    root.debug("filled mdc, key2 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern4);
  +    layout.activateOptions();
  +    root.debug("filled mdc, key3 in pattern");
  +    
  +    layout.setConversionPattern(mdcMsgPattern5);
  +    layout.activateOptions();
  +    root.debug("filled mdc, key1, key2, and key3 in pattern");
  +
  +    MDC.remove("key1");
  +    MDC.remove("key2");
  +
  +    layout.setConversionPattern("%m%n");
  +    layout.activateOptions();
  +    root.debug("finished mdc pattern test");
  +
  +    assertTrue(Compare.compare(OUTPUT_FILE, WITNESS_FILE));
  +  }
  +
     public static Test suite() {
       TestSuite suite = new TestSuite();
       suite.addTest(new PatternLayoutTest("test1"));
  @@ -395,7 +471,8 @@
       suite.addTest(new PatternLayoutTest("test12"));
       suite.addTest(new PatternLayoutTest("test13"));
       suite.addTest(new PatternLayoutTest("test14"));
  -    suite.addTest(new PatternLayoutTest("testMDCAllowAllKeys"));
  +    suite.addTest(new PatternLayoutTest("testMDC1"));
  +    suite.addTest(new PatternLayoutTest("testMDC2"));
       
       return suite;
     }
  
  
  
  1.2       +1 -1      jakarta-log4j/examples/jmx/T.java
  
  Index: T.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/jmx/T.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- T.java	23 Oct 2002 12:01:00 -0000	1.1
  +++ T.java	18 Sep 2003 21:26:55 -0000	1.2
  @@ -1,4 +1,4 @@
  -package examples.jmx;
  +package jmx;
   
   import org.apache.log4j.jmx.Agent;
   import org.apache.log4j.Category;
  
  
  
  1.40      +0 -1      jakarta-log4j/src/java/org/apache/log4j/FileAppender.java
  
  Index: FileAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/FileAppender.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- FileAppender.java	23 Aug 2003 16:00:52 -0000	1.39
  +++ FileAppender.java	18 Sep 2003 21:26:55 -0000	1.40
  @@ -183,7 +183,6 @@
         try {
           setFile(fileName, fileAppend, bufferedIO, bufferSize);
         } catch (java.io.IOException e) {
  -        System.out.println("xx" + fileName);
           errorHandler.error(
             "setFile(" + fileName + "," + fileAppend + ") call failed.", e,
             ErrorCode.FILE_OPEN_FAILURE);
  
  
  
  1.23      +2 -16     jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java
  
  Index: PatternLayout.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/PatternLayout.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- PatternLayout.java	17 Sep 2003 17:02:52 -0000	1.22
  +++ PatternLayout.java	18 Sep 2003 21:26:55 -0000	1.23
  @@ -458,11 +458,8 @@
        Constructs a PatternLayout using the supplied conversion pattern.
     */
     public PatternLayout(String pattern) {
  -    //System.out.println("...PatternLayout ["+pattern+"], "+this);
       this.conversionPattern = pattern;
  -    head =
  -      createPatternParser(
  -        (pattern == null) ? DEFAULT_CONVERSION_PATTERN : pattern).parse();
  +    activateOptions();
     }
   
     /**
  @@ -510,7 +507,7 @@
       you change the parameters of the PatternLayout instance.
     */
     public void activateOptions() {
  -    PatternParser patternParser = createPatternParser(conversionPattern);
  +    PatternParser patternParser = new PatternParser(conversionPattern);
       patternParser.setConverterRegistry(ruleRegistry);
       head = patternParser.parse();
     }
  @@ -523,17 +520,6 @@
         @since 0.8.4 */
     public boolean ignoresThrowable() {
       return true;
  -  }
  -
  -  /**
  -    Returns PatternParser used to parse the conversion string. Subclasses
  -    may override this to return a subclass of PatternParser which recognize
  -    custom conversion characters.
  -
  -    @since 0.9.0
  -  */
  -  protected PatternParser createPatternParser(String pattern) {
  -    return new PatternParser(pattern);
     }
   
     /**
  
  
  
  1.1                  jakarta-log4j/tests/src/java/org/apache/log4j/pattern/Num343PatternConverter.java
  
  Index: Num343PatternConverter.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.pattern;
  
  import org.apache.log4j.spi.LoggingEvent;
  
  
  public class Num343PatternConverter extends PatternConverter {
    StringBuffer buf;
  
    public Num343PatternConverter() {
      super();
      this.buf = new StringBuffer(5);
    }
  
    public StringBuffer convert(LoggingEvent event) {
      buf.setLength(0);
      buf.append("343");
  
      return buf;
    }
  }
  
  
  
  1.1                  jakarta-log4j/tests/src/java/org/apache/log4j/pattern/PatternParserTest.java
  
  Index: PatternParserTest.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.pattern;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import org.apache.log4j.Level;
  import org.apache.log4j.Logger;
  import org.apache.log4j.spi.LoggingEvent;
  
  import java.io.CharArrayWriter;
  
  import java.util.HashMap;
  
  
  /**
     Test case for helpers/PatternParser.java. Tests the various
     conversion patterns supported by PatternParser. This test
     class tests PatternParser via the PatternLayout class which
     uses it.
   */
  public class PatternParserTest extends TestCase {
    public CharArrayWriter charArrayWriter = new CharArrayWriter(1024);
    Logger logger = Logger.getLogger(PatternParserTest.class);
  
    public PatternParserTest(String name) {
      super(name);
    }
  
    public void setUp() {
      charArrayWriter.reset();
    }
  
    public void tearDown() {
    }
  
    String convert(LoggingEvent event, PatternConverter head)
      throws Exception {
      PatternConverter c = head;
  
      while (c != null) {
        System.out.println("pc "+c);
        c.format(charArrayWriter, event);
        c = c.next;
      }
  
      return charArrayWriter.toString();
    }
  
    public void testNewWord() throws Exception {
      PatternParser patternParser = new PatternParser("%zum343");
      HashMap ruleRegistry = new HashMap(5);
  
      ruleRegistry.put("zum343", Num343PatternConverter.class.getName());
      patternParser.setConverterRegistry(ruleRegistry);
  
      PatternConverter head = patternParser.parse();
  
      LoggingEvent event =
        new LoggingEvent(
          Logger.class.getName(), logger, Level.DEBUG, "msg 1", null);
      String result = convert(event, head);
      System.out.println("Resuls is["+result+"]");
      assertEquals("343", result);
    }
  
    public static Test suite() {
      TestSuite suite = new TestSuite();
      suite.addTest(new PatternParserTest("testNewWord"));
  
      return suite;
    }
  }
  
  
  
  1.75      +7 -3      jakarta-log4j/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/build.xml,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- build.xml	12 Sep 2003 18:10:17 -0000	1.74
  +++ build.xml	18 Sep 2003 21:26:55 -0000	1.75
  @@ -28,6 +28,9 @@
     <!-- Destination for compiled files -->
     <property name="javac.dest" value="dist/classes"/>
   
  +  <!-- Destination for compiled files for examples/ -->
  +  <property name="examples.javac.dest" value="examples/classes"/>
  +
     <!-- Destination for generated jar files -->
     <property name="jar.dest" value="${basedir}"/>
   
  @@ -213,9 +216,9 @@
     </target>
   
     <target name="build.examples" depends="build.core">
  -    <mkdir dir="${javac.dest}" />
  +    <mkdir dir="${examples.javac.dest}" />
       <javac srcdir="${basedir}"
  -     destdir="${javac.dest}"
  +     destdir="${examples.javac.dest}"
        includes="examples/**/*.java"
        excludes="misc/*, examples/jmx/*.java"
        deprecation="${deprecation}"
  @@ -223,7 +226,7 @@
         <classpath refid="compile.classpath"/>
       </javac>
   
  -    <rmic base="${javac.dest}" classname="examples.NumberCruncherServer" />
  +    <rmic base="${examples.javac.dest}" classname="factor.NumberCruncherServer" />
   
       <copy todir="${javac.dest}">
         <fileset dir="." includes="examples/lf5/**/*.properties"/>
  @@ -299,6 +302,7 @@
     <!-- ================================================================= -->
     <target name="clean" depends="init" description="Delete all compiled files.">
       <delete dir="${javac.dest}/" />
  +    <delete dir="${examples.javac.dest}/" />
     </target>
   
     <!-- ================================================================= -->
  
  
  
  1.4       +1 -1      jakarta-log4j/tests/input/patternLayout14.properties
  
  Index: patternLayout14.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/input/patternLayout14.properties,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- patternLayout14.properties	25 Apr 2002 14:09:01 -0000	1.3
  +++ patternLayout14.properties	18 Sep 2003 21:26:55 -0000	1.4
  @@ -2,5 +2,5 @@
   log4j.appender.testAppender=org.apache.log4j.FileAppender
   log4j.appender.testAppender.File=       output/temp 
   log4j.appender.testAppender.Append=false
  -log4j.appender.testAppender.layout=org.apache.log4j.MyPatternLayout
  +log4j.appender.testAppender.layout=pattern.MyPatternLayout
   log4j.appender.testAppender.layout.ConversionPattern=%5p %-4# - %m%n
  
  
  
  1.2       +72 -38    jakarta-log4j/examples/customLevel/XLevel.java
  
  Index: XLevel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/customLevel/XLevel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- XLevel.java	19 Feb 2002 10:31:32 -0000	1.1
  +++ XLevel.java	18 Sep 2003 21:26:55 -0000	1.2
  @@ -1,5 +1,53 @@
  +/*
  + * ============================================================================
  + *                   The Apache Software License, Version 1.1
  + * ============================================================================
  + *
  + *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  + *
  + * Redistribution and use in source and binary forms, with or without modifica-
  + * tion, are permitted provided that the following conditions are met:
  + *
  + * 1. Redistributions of  source code must  retain the above copyright  notice,
  + *    this list of conditions and the following disclaimer.
  + *
  + * 2. Redistributions in binary form must reproduce the above copyright notice,
  + *    this list of conditions and the following disclaimer in the documentation
  + *    and/or other materials provided with the distribution.
  + *
  + * 3. The end-user documentation included with the redistribution, if any, must
  + *    include  the following  acknowledgment:  "This product includes  software
  + *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
  + *    Alternately, this  acknowledgment may  appear in the software itself,  if
  + *    and wherever such third-party acknowledgments normally appear.
  + *
  + * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
  + *    endorse  or promote  products derived  from this  software without  prior
  + *    written permission. For written permission, please contact
  + *    apache@apache.org.
  + *
  + * 5. Products  derived from this software may not  be called "Apache", nor may
  + *    "Apache" appear  in their name,  without prior written permission  of the
  + *    Apache Software Foundation.
  + *
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  + * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  + * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
  + * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
  + * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
  + * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
  + * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
  + * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
  + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  + *
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation.  For more  information on the
  + * Apache Software Foundation, please see <http://www.apache.org/>.
  + *
  + */
   
  -package examples.customLevel;
  +package customLevel;
   
   import org.apache.log4j.Level;
   import org.apache.log4j.Priority;
  @@ -11,64 +59,50 @@
   
    */
   public class XLevel extends Level {
  -
  -  static public final int  TRACE_INT   = Level.DEBUG_INT - 1;
  -  static public final int  LETHAL_INT  = Level.FATAL_INT + 1;
  -
  -
  -  private static String TRACE_STR  = "TRACE";
  -  private static String LETHAL_STR  = "LETHAL";
  -
  -
  +  public static final int TRACE_INT = Level.DEBUG_INT - 1;
  +  public static final int LETHAL_INT = Level.FATAL_INT + 1;
  +  private static String TRACE_STR = "TRACE";
  +  private static String LETHAL_STR = "LETHAL";
     public static final XLevel TRACE = new XLevel(TRACE_INT, TRACE_STR, 7);
  -  public static final XLevel LETHAL = new XLevel(LETHAL_INT, LETHAL_STR, 
  -						       0);
  +  public static final XLevel LETHAL = new XLevel(LETHAL_INT, LETHAL_STR, 0);
   
  -
  -  protected
  -  XLevel(int level, String strLevel, int syslogEquiv) {
  +  protected XLevel(int level, String strLevel, int syslogEquiv) {
       super(level, strLevel, syslogEquiv);
     }
   
     /**
        Convert the string passed as argument to a level. If the
  -     conversion fails, then this method returns {@link #TRACE}. 
  +     conversion fails, then this method returns {@link #TRACE}.
     */
  -  public
  -  static
  -  Level toLevel(String sArg) {
  +  public static Level toLevel(String sArg) {
       return (Level) toLevel(sArg, XLevel.TRACE);
     }
   
  -
  -  public
  -  static
  -  Level toLevel(String sArg, Level defaultValue) {
  -
  -    if(sArg == null) {
  +  public static Level toLevel(String sArg, Level defaultValue) {
  +    if (sArg == null) {
         return defaultValue;
       }
  +
       String stringVal = sArg.toUpperCase();
  -    
  -    if(stringVal.equals(TRACE_STR)) {
  +
  +    if (stringVal.equals(TRACE_STR)) {
         return XLevel.TRACE;
  -    } else if(stringVal.equals(LETHAL_STR)) {
  +    } else if (stringVal.equals(LETHAL_STR)) {
         return XLevel.LETHAL;
       }
  -      
  -    return Level.toLevel(sArg, (Level) defaultValue);    
  +
  +    return Level.toLevel(sArg, (Level) defaultValue);
     }
   
  +  public static Level toLevel(int i) throws IllegalArgumentException {
  +    switch (i) {
  +    case TRACE_INT:
  +      return XLevel.TRACE;
   
  -  public
  -  static
  -  Level toLevel(int i) throws  IllegalArgumentException {
  -    switch(i) {
  -    case TRACE_INT: return XLevel.TRACE;
  -    case LETHAL_INT: return XLevel.LETHAL;
  +    case LETHAL_INT:
  +      return XLevel.LETHAL;
       }
  +
       return Level.toLevel(i);
     }
  -
   }
  -  
  
  
  
  1.4       +2 -2      jakarta-log4j/examples/subclass/MyLogger.java
  
  Index: MyLogger.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/subclass/MyLogger.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MyLogger.java	18 Feb 2002 17:36:36 -0000	1.3
  +++ MyLogger.java	18 Sep 2003 21:26:55 -0000	1.4
  @@ -5,12 +5,12 @@
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
   
  -package examples.subclass;
  +package subclass;
   
   import org.apache.log4j.*;
   import org.apache.log4j.spi.LoggerFactory;
   import org.apache.log4j.xml.DOMConfigurator;
  -import examples.customLevel.XLevel;
  +import customLevel.XLevel;
   import org.apache.log4j.PropertyConfigurator;
   import org.apache.log4j.helpers.LogLog;
   
  
  
  
  1.3       +1 -1      jakarta-log4j/examples/subclass/MyLoggerFactory.java
  
  Index: MyLoggerFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/subclass/MyLoggerFactory.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- MyLoggerFactory.java	11 Feb 2002 16:14:33 -0000	1.2
  +++ MyLoggerFactory.java	18 Sep 2003 21:26:55 -0000	1.3
  @@ -5,7 +5,7 @@
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
   
  -package examples.subclass;
  +package subclass;
   
   import org.apache.log4j.Logger;
   import org.apache.log4j.spi.LoggerFactory;
  
  
  
  1.4       +2 -2      jakarta-log4j/examples/subclass/MyLoggerTest.java
  
  Index: MyLoggerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/examples/subclass/MyLoggerTest.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MyLoggerTest.java	18 Feb 2002 17:36:36 -0000	1.3
  +++ MyLoggerTest.java	18 Sep 2003 21:26:55 -0000	1.4
  @@ -5,12 +5,12 @@
    * License version 1.1, a copy of which has been included with this
    * distribution in the LICENSE.txt file.  */
   
  -package examples.subclass;
  +package subclass;
   
   import org.apache.log4j.*;
   import org.apache.log4j.spi.LoggerFactory;
   import org.apache.log4j.xml.DOMConfigurator;
  -import examples.customLevel.XLevel;
  +import customLevel.XLevel;
   import org.apache.log4j.PropertyConfigurator;
   import org.apache.log4j.helpers.LogLog;
   
  
  
  
  1.1                  jakarta-log4j/examples/subclass/mycat.bad
  
  Index: mycat.bad
  ===================================================================
  
  # The usual stuff. Note that A1 is configured in root not in "some.cat"
  log4j.rootLogger=DEBUG, A1
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%5p [%t] %c - %m%n
  
  # Set the priority of "some.cat" to TRACE (defined in
  # examples.customLevel.XLevel). This will actually have the side
  # effect of instanciating a logger object having the name "some.cat"
  # this will cause a ClassCastException if the logger object is cast
  # as a MyLogger object.
  
  log4j.logger.some.cat=TRACE#examples.customLevel.XLevel
  
  
  
  
  
  
  1.1                  jakarta-log4j/examples/subclass/mycat.good
  
  Index: mycat.good
  ===================================================================
  # Setting the logger factory to MyLoggerFactory solves the
  # ClassCastException problem encountered with the "mycat.bad"
  # configuration file.
  
  log4j.loggerFactory=examples.subclass.MyLoggerFactory
  
  
  # The usual stuff. Note that A1 is configured in root not in "some.cat"
  
  log4j.rootLogger=DEBUG, A1
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%5p [%t] %c - %m%n
  
  
  # Set the priority of "some.cat" to TRACE (defined in
  # examples.customLevel.XLevel). Since we specified MyLoggerFactory as
  # the logger factory, the following line willl also have the side
  # effect of instanciating a MyLogger object having the name
  # "some.cat".
  
  log4j.logger.some.cat=TRACE#examples.customLevel.XLevel
  
  
  
  
  1.1                  jakarta-log4j/examples/trivial/Trivial.java
  
  Index: Trivial.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package trivial;
  
  import org.apache.log4j.BasicConfigurator;
  import org.apache.log4j.Category;
  import org.apache.log4j.NDC;
  
  
  /**
     View the <a href="doc-files/Trivial.java">source code</a> of this a
     trivial usage example. Running <code>java examples.Trivial</code>
     should output something similar to:
  
     <pre>
        0    INFO  [main] examples.Trivial (Client #45890) - Awake awake. Put on thy strength.
        15   DEBUG [main] examples.Trivial (Client #45890 DB) - Now king David was old.
        278  INFO  [main] examples.Trivial$InnerTrivial (Client #45890) - Entered foo.
        293  INFO  [main] examples.Trivial (Client #45890) - Exiting Trivial.
     </pre>
  
     <p> The increasing numbers at the beginning of each line are the
     times elapsed since the start of the program. The string between
     the parentheses is the nested diagnostic context.
  
     <p>See {@link Sort} and {@link SortAlgo} for sligtly more elaborate
     examples.
  
     <p>Note thent class files for the example code is not included in
     any of the distributed log4j jar files. You will have to add the
     directory <code>/dir-where-you-unpacked-log4j/classes</code> to
     your classpath before trying out the examples.
  
   */
  public class Trivial {
    static Category cat = Category.getInstance(Trivial.class.getName());
  
    public static void main(String[] args) {
      BasicConfigurator.configure();
      NDC.push("Client #45890");
  
      cat.info("Awake awake. Put on thy strength.");
      Trivial.foo();
      InnerTrivial.foo();
      cat.info("Exiting Trivial.");
    }
  
    static void foo() {
      NDC.push("DB");
      cat.debug("Now king David was old.");
      NDC.pop();
    }
  
    static class InnerTrivial {
      static Category cat = Category.getInstance(InnerTrivial.class.getName());
  
      static void foo() {
        cat.info("Entered foo.");
      }
    }
  }
  
  
  
  1.1                  jakarta-log4j/examples/factor/NumberCruncher.java
  
  Index: NumberCruncher.java
  ===================================================================
  
  package factor;
  
  import java.rmi.Remote;
  import java.rmi.RemoteException;
  
  /**
     NumberCruncher's factor positive integers. See <a
     href=doc-files/NumberCruncher.java>source</a> code for more details.
  
     @author Ceki G&uuml;lc&uuml;
     
  */
  public interface NumberCruncher extends Remote {
  
    /**
       Factor a positive integer <code>number</code> and return its
       <em>distinct</em> factor's as an integer array.
    */
    int[] factor(int number) throws RemoteException;
  }
  
  
  
  1.1                  jakarta-log4j/examples/factor/NumberCruncherClient.java
  
  Index: NumberCruncherClient.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.APL file.  */
  
  package factor;
  
  import java.rmi.Remote;
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.RemoteException;
  import java.rmi.Naming;
  import java.util.Vector;
  import java.io.*;
  
  /**
     NumberCruncherClient is a simple client for factoring integers. A
     remote NumberCruncher is contacted and asked to factor an
     integer. The factors returned by the {@link NumberCruncherServer}
     are displayed on the screen.
  
     <p>See <a href=doc-files/NumberCruncherClient.java>source</a> code of 
     <code>NumberCruncherClient</code> for more details.
  
     <pre>
     <b>Usage:</b> java  org.apache.log4j.examples.NumberCruncherClient HOST
      &nbsp;&nbsp;&nbsp;&nbsp;where HOST is the machine where the NumberCruncherServer is running
     </pre>
     
     <p>Note that class files for the example code is not included in
     any of the distributed log4j jar files. You will have to add the
     directory <code>/dir-where-you-unpacked-log4j/classes</code> to
     your classpath before trying out the examples.
  
     @author Ceki G&uuml;lc&uuml;
     
   */
  public class NumberCruncherClient {
  
  
    public static void main(String[] args) {
      if(args.length == 1) {
        try {
          String url = "rmi://"+args[0]+ "/Factor";
        	NumberCruncher nc = (NumberCruncher) Naming.lookup(url);
  	loop(nc);
        }
        catch(Exception e) {
  	e.printStackTrace();
        }      
      }
      else
        usage("Wrong number of arguments.");
    }
  
    static
    void usage(String msg) {
      System.err.println(msg);
      System.err.println(
       "Usage: java org.apache.log4j.examples.NumberCruncherClient HOST\n" +
       "   where HOST is the machine where the NumberCruncherServer is running.");
      System.exit(1);
    }
  
  
    static
    void loop(NumberCruncher nc) {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int i = 0;
      while (true) {
        System.out.print("Enter a number to factor, '-1' to quit: ");      
        try {
  	i = Integer.parseInt(in.readLine());
        }
        catch(Exception e) {
  	e.printStackTrace();
        }
        if(i == -1) {
  	System.out.print("Exiting loop.");
  	return;
        }
        else {
  	try {
  	  System.out.println("Will attempt to factor "+i);
  	  int[] factors = nc.factor(i);
  	  System.out.print("The factors of "+i+" are");
  	  for(int k=0; k < factors.length; k++) {
  	    System.out.print(" " + factors[k]);
  	  }
  	  System.out.println(".");
  	}
  	catch(RemoteException e) {
  	  System.err.println("Could not factor "+i);
  	  e.printStackTrace();
  	}
        }
      }
    }
  }
  
  
  
  1.1                  jakarta-log4j/examples/factor/NumberCruncherServer.java
  
  Index: NumberCruncherServer.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software
   * License version 1.1, a copy of which has been included with this
   * distribution in the LICENSE.APL file.  */
  
  package factor;
  
  import java.rmi.Remote;
  import java.rmi.server.UnicastRemoteObject;
  import java.rmi.RemoteException;
  import java.rmi.Naming;
  import java.util.Vector;
  
  
  import org.apache.log4j.Category;
  import org.apache.log4j.NDC;
  import org.apache.log4j.PropertyConfigurator;
  
  /**
     A simple {@link NumberCruncher} implementation that logs its
     progress when factoring numbers. The purpose of the whole exercise
     is to show the use of nested diagnostic contexts in order to
     distinguish the log output from different client requests.
  
     <pre>
     <b>Usage:</b> java org.apache.log4j.examples.NumberCruncherServer <em>configFile</em>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where <em>configFile</em> is a log4j configuration file.
     </pre>
  
     We supply a simple config file <a href=doc-files/factor.lcf>factor.lcf</a>
     for directing log output to the file <code>factor.log</code>.
  
     <p>Try it yourself by starting a <code>NumberCruncherServer</code>
     and make queries from multiple {@link NumberCruncherClient
     NumberCruncherClients} to factor numbers.
  
     
     <p><b><a href="doc-files/factor.html">Sample output</a></b> shows the log
     output when two clients connect to the server near simultaneously.
        
     <p>See <a href=doc-files/NumberCruncherServer.java>source</a> code
     of <code>NumberCruncherServer</code> for more details.
  
     <p>Note that class files for the example code is not included in
     any of the distributed log4j jar files. You will have to add the
     directory <code>/dir-where-you-unpacked-log4j/classes</code> to
     your classpath before trying out the examples.
  
     
   */
  public class NumberCruncherServer extends UnicastRemoteObject
                                    implements  NumberCruncher {
  
  
    static Category cat = Category.getInstance(
  					NumberCruncherServer.class.getName());
  
    public
    NumberCruncherServer() throws RemoteException {
    }
    
    public
    int[] factor(int number) throws RemoteException {
  
      // The client's host is an important source of information.
      try {
        NDC.push(this.getClientHost());
      }
      catch(java.rmi.server.ServerNotActiveException e) {
        // we are being called from same VM
        NDC.push("localhost");
      }
  
      // The information contained within the request is another source of
      // distinctive information. It might reveal the users name, date of request,
      // request ID etc. In servlet type environments, much information is
      // contained in cookies.
      NDC.push(String.valueOf(number));    
  
      cat.info("Beginning to factor.");
      if(number <= 0) {
        throw new IllegalArgumentException(number+" is not a positive integer.");
      }
      else if(number == 1)
         return new int[] {1};
      
      Vector factors = new Vector();
      int n = number;
  
      for(int i = 2; (i <= n) && (i*i <= number); i++) {
        // It is bad practice to place log requests within tight loops.
        // It is done here to show interleaved log output from
        // different requests. 
        cat.debug("Trying to see if " + i + " is a factor.");
  
        if((n % i) == 0) {
  	cat.info("Found factor "+i);
  	factors.addElement(new Integer(i));
  	do {
  	  n /= i;
  	} while((n % i) == 0);
        }
        // Placing artificial delays in tight-loops will also lead to sub-optimal
        // resuts. :-)
        delay(100);
      }
  
      if(n != 1) {
        cat.info("Found factor "+n);
        factors.addElement(new Integer(n));
      }
      
      int len = factors.size();
      
      int[] result = new int[len];
      for(int i = 0; i < len; i++) {
        result[i] = ((Integer) factors.elementAt(i)).intValue();
      }
  
      // Before leaving a thread we call NDC.remove. This deletes the reference
      // to the thread in the internal hash table. Version 0.8.5 introduces a
      // a lazy removal mechanism in case you forget to call remove when
      // exiting a thread. See the java documentation in NDC.remove for further
      // details.
      NDC.remove();
      
      return result;
    }
  
    static
    void usage(String msg) {
      System.err.println(msg);
      System.err.println(
       "Usage: java org.apache.log4j.examples.NumberCruncherServer configFile\n" +
       "   where configFile is a log4j configuration file.");
      System.exit(1);
    }
  
    public static
    void delay(int millis) {
      try{Thread.currentThread().sleep(millis);}
      catch(InterruptedException e) {}
    }
    
    public static void main(String[] args) {
      if(args.length != 1) 
        usage("Wrong number of arguments.");
      
      NumberCruncherServer ncs;
      PropertyConfigurator.configure(args[0]);
      try {
        ncs = new NumberCruncherServer();
        Naming.rebind("Factor", ncs);
        cat.info("NumberCruncherServer bound and ready to serve.");
      }
      catch(Exception e) {
        cat.error("Could not bind NumberCruncherServer.", e);
        return;
      }
      NumberCruncherClient.loop(ncs);          
    }
  }
  
  
  
  1.1                  jakarta-log4j/examples/factor/factor.html
  
  Index: factor.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <html> <head>
  <title></title>
  </head>
  
  <body bgcolor=white>
  <center><h2>Log4j output of two near-simultaneous requests</h2></center>
  
  <p>Here is the logged output when two clients ask to factor two
  integers near-simultanesouly. The client on the host 128.178.50.84
  asks to factor the prime number 359.  The client on the host 9.4.2.196
  asks to factor the number 347 (also a prime).
  
  <p>The NDC is placed between parantheses in bold. The NDC information
  consists of the client's host and the number to factor. Since the two
  requests have distinct NDCs, their output can be easily separated.
  
  <pre>
  0      INFO  [main] <b>()</b> - NumberCruncherServer bound and ready to serve.
  276493 INFO  [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Beginning to factor.
  276495 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 2 is a factor.
  276699 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 3 is a factor.
  276908 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 4 is a factor.
  276983 INFO  [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Beginning to factor.
  276984 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 2 is a factor.
  277115 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 5 is a factor.
  277188 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 3 is a factor.
  277318 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 6 is a factor.
  277398 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 4 is a factor.
  277520 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 7 is a factor.
  277605 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347) </b>- Trying to see if 5 is a factor.
  277728 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 8 is a factor.
  277808 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 6 is a factor.
  277931 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 9 is a factor.
  278019 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 7 is a factor.
  278138 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 10 is a factor.
  278228 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 8 is a factor.
  278348 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 11 is a factor.
  278438 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 9 is a factor.
  278559 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 12 is a factor.
  278648 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 10 is a factor.
  278768 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 13 is a factor.
  278858 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 11 is a factor.
  278970 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 14 is a factor.
  279068 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 12 is a factor.
  279178 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 15 is a factor.
  279270 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 13 is a factor.
  279387 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 16 is a factor.
  279478 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 14 is a factor.
  279598 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 17 is a factor.
  279688 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 15 is a factor.
  279808 DEBUG [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Trying to see if 18 is a factor.
  279898 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 16 is a factor.
  280018 INFO  [RMI TCP Connection(7)-128.178.50.84] <b>(128.178.50.84 359)</b> - Found factor 359
  280108 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 17 is a factor.
  280318 DEBUG [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Trying to see if 18 is a factor.
  280520 INFO  [RMI TCP Connection(8)-9.4.2.196] <b>(9.4.2.196 347)</b> - Found factor 347
  </pre>
  
  
  <hr>
  <address></address>
  <!-- hhmts start -->
  Last modified: Fri May  5 10:36:05 MDT 2000
  <!-- hhmts end -->
  </body> </html>
  
  
  
  1.1                  jakarta-log4j/examples/factor/factor.lcf
  
  Index: factor.lcf
  ===================================================================
  # For the general syntax of property based configuration files see the
  # documenation of org.apache.log4j.PropertyConfigurator.
  
  # The root category uses the appender called A1. Since no priority is
  # specified, the root category assumes the default priority for root
  # which is DEBUG in log4j. The root category is the only category that
  # has a default priority. All other categories need not be assigned a
  # priority in which case they inherit their priority from the
  # hierarchy.
  
  log4j.rootCategory=, A1
  
  # A1 is set to be a FileAppender which outputs to the file
  # "factor.log". Start the server NumberCruncherServer and two
  # NumberCruncherClients, and ask to factor two numbers
  # near-simultaneously. Notice that the log output from these two
  # requests are logged in the file factor.log. Nevertheless, the logs
  # of these requests can still be distinguished given their distinct
  # nested diagnostic contexts.
    
  log4j.appender.A1=org.apache.log4j.FileAppender
  log4j.appender.A1.File=factor.log
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  
  # Note the %x conversion specifier for NDC printing.
  log4j.appender.A1.layout.ConversionPattern=%-4r %-5p [%t] (%x) - %m\n
  
  
  
  
  1.1                  jakarta-log4j/tests/witness/patternLayout.mdc.2
  
  Index: patternLayout.mdc.2
  ===================================================================
  starting mdc pattern test
  empty mdc, no key specified in pattern : {}
  empty mdc, key1 in pattern : 
  empty mdc, key2 in pattern : 
  empty mdc, key3 in pattern : 
  empty mdc, key1, key2, and key3 in pattern : ,,
  filled mdc, no key specified in pattern : {{key2,value2}{key1,value1}}
  filled mdc, key1 in pattern : value1
  filled mdc, key2 in pattern : value2
  filled mdc, key3 in pattern : 
  filled mdc, key1, key2, and key3 in pattern : value1,value2,
  finished mdc pattern test
  
  
  
  1.42      +4 -2      jakarta-log4j/tests/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/build.xml,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- build.xml	17 Sep 2003 18:03:16 -0000	1.41
  +++ build.xml	18 Sep 2003 21:26:55 -0000	1.42
  @@ -16,13 +16,15 @@
     <!-- The directory where source files are stored. -->
     <property name="project.source.home" value="../src/java/"/>
     <property name="project.classes.home" value="../dist/classes/"/>
  -
  +  <property name="examples.classes" value="../examples/classes/"/>
  +  
     <property name="tests.source.home" value="./src/java/"/>
   
   
     <path id="tests.classpath">
       <pathelement location="${project.source.home}"/>
       <pathelement location="${project.classes.home}"/>
  +    <pathelement location="${examples.classes}"/>
       <pathelement location="${tests.source.home}"/>
       <pathelement location="./classes"/>
       <pathelement location="./resources"/>
  @@ -333,7 +335,7 @@
       <junit printsummary="yes" fork="yes" haltonfailure="yes">
         <classpath refid="tests.classpath"/>
         <formatter type="plain" usefile="false"/>
  -      <test name="org.apache.log4j.helpers.PatternParserTestCase" />
  +      <test name="org.apache.log4j.pattern.PatternParserTest" />
       </junit>
     </target>
   
  
  
  
  1.5       +19 -9     jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java
  
  Index: PatternParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/pattern/PatternParser.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PatternParser.java	12 Sep 2003 18:24:26 -0000	1.4
  +++ PatternParser.java	18 Sep 2003 21:26:55 -0000	1.5
  @@ -56,7 +56,6 @@
   import org.apache.log4j.helpers.OptionConverter;
   
   import java.util.HashMap;
  -import java.util.Hashtable;
   
   
   // Contributors:   Nelson Minar <(nelson@monkey.org>
  @@ -70,7 +69,7 @@
      <p>It is this class that parses conversion patterns and creates
      a chained list of {@link OptionConverter OptionConverters}.
   
  -   @author <a href=mailto:"cakalijp@Maritz.com">James P. Cakalic</a>
  +   @author James P. Cakalic
      @author Ceki G&uuml;lc&uuml;
      @author Anders Kristensen
   
  @@ -94,9 +93,11 @@
     static final int LEVEL_CONVERTER = 2002;
     static final int NDC_CONVERTER = 2003;
     static final int MESSAGE_CONVERTER = 2004;
  +  
     static HashMap globalRulesRegistry;
  -
  + 
     static {
  +    // We set the global rules in the static initializer of PatternParser class
       globalRulesRegistry = new HashMap(17);
       globalRulesRegistry.put("c", LoggerPatternConverter.class.getName());
       globalRulesRegistry.put("C", ClassNamePatternConverter.class.getName());
  @@ -104,6 +105,7 @@
       globalRulesRegistry.put("l", FullLocationPatternConverter.class.getName()); 
       globalRulesRegistry.put("L", LineLocationPatternConverter.class.getName());
       globalRulesRegistry.put("m", MessagePatternConverter.class.getName());
  +    globalRulesRegistry.put("n", LineSeparatorPatternConverter.class.getName());
       globalRulesRegistry.put(
         "M", MethodLocationPatternConverter.class.getName());
       globalRulesRegistry.put("p", LevelPatternConverter.class.getName());
  @@ -123,6 +125,12 @@
     PatternConverter tail;
     protected FormattingInfo formattingInfo = new FormattingInfo();
     protected String pattern;
  +  
  +  /**
  +   * Additional rules for this particular instance.
  +   * key: the conversion word (as String)
  +   * value: the pattern converter class (as String) 
  +   */
     HashMap converterRegistry;
   
     static Logger logger  = Logger.getLogger("LOG4J."+PatternParser.class.getName());
  @@ -224,12 +232,6 @@
   
               break;
   
  -          case 'n':
  -            currentLiteral.append(Layout.LINE_SEP);
  -            i++; // move pointer
  -
  -            break;
  -
             default:
   
               if (currentLiteral.length() != 0) {
  @@ -364,6 +366,8 @@
       //System.out.println("c is [" + c + "]");
       String className = (String) findConverterClass(converterId);
   
  +    //System.out.println("==============[" + className + "]");
  +    
       String option = extractOption();
   
       //System.out.println("Option is [" + option + "]");
  @@ -438,10 +442,16 @@
       formattingInfo.reset();
     }
   
  +  /**
  +   * Returns the converter registry for this PatternParser instance.
  +   */
     public HashMap getConverterRegistry() {
       return converterRegistry;
     }
   
  +  /**
  +   * Set the converter registry for this PatternParser instance.
  +   */
     public void setConverterRegistry(HashMap converterRegistry) {
       this.converterRegistry = converterRegistry;
     }
  
  
  
  1.1                  jakarta-log4j/src/java/org/apache/log4j/pattern/LineSeparatorPatternConverter.java
  
  Index: LineSeparatorPatternConverter.java
  ===================================================================
  /*
   * ============================================================================
   *                   The Apache Software License, Version 1.1
   * ============================================================================
   *
   *    Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without modifica-
   * tion, are permitted provided that the following conditions are met:
   *
   * 1. Redistributions of  source code must  retain the above copyright  notice,
   *    this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   *
   * 3. The end-user documentation included with the redistribution, if any, must
   *    include  the following  acknowledgment:  "This product includes  software
   *    developed  by the  Apache Software Foundation  (http://www.apache.org/)."
   *    Alternately, this  acknowledgment may  appear in the software itself,  if
   *    and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "log4j" and  "Apache Software Foundation"  must not be used to
   *    endorse  or promote  products derived  from this  software without  prior
   *    written permission. For written permission, please contact
   *    apache@apache.org.
   *
   * 5. Products  derived from this software may not  be called "Apache", nor may
   *    "Apache" appear  in their name,  without prior written permission  of the
   *    Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   * FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   * APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   * INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   * DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   * OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   * ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   * (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   *
   * This software  consists of voluntary contributions made  by many individuals
   * on  behalf of the Apache Software  Foundation.  For more  information on the
   * Apache Software Foundation, please see <http://www.apache.org/>.
   *
   */
  
  package org.apache.log4j.pattern;
  
  import org.apache.log4j.Layout;
  import org.apache.log4j.spi.LoggingEvent;
  
  
  /**
   * Return the line separator for the current system.
   *  
   * @author Ceki G&uuml;lc&uuml;
   */
  public class LineSeparatorPatternConverter extends PatternConverter {
  
    StringBuffer buf;
  
    public LineSeparatorPatternConverter() {
      super();
      this.buf = new StringBuffer(Layout.LINE_SEP_LEN);
      buf.append(Layout.LINE_SEP);
    }
  
    public StringBuffer convert(LoggingEvent event) {
      return buf;
    }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message