You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-cvs@jakarta.apache.org by ce...@apache.org on 2001/01/23 23:07:45 UTC

cvs commit: jakarta-log4j/org/apache/log4j/test UnitTestBoundedFIFO.java unitTest

ceki        01/01/23 14:07:45

  Modified:    doc      FAQ.html HISTORY deepExtension.html manual.html
               org/apache/log4j AsyncAppender.java
               org/apache/log4j/helpers BoundedFIFO.java
               org/apache/log4j/test UnitTestBoundedFIFO.java unitTest
  Log:
  Added the BufferSize option to the AsyncAppender and updated UnitTestBoundedFIFO to test this new feature.
  
  Revision  Changes    Path
  1.3       +5 -5      jakarta-log4j/doc/FAQ.html
  
  Index: FAQ.html
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/doc/FAQ.html,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FAQ.html	2001/01/18 07:49:37	1.2
  +++ FAQ.html	2001/01/23 22:07:22	1.3
  @@ -199,7 +199,7 @@
   The log output can be customized in many ways. Moreover, one can completely
   override the output format by implementing one's own Layout. 
   
  -<p>Here is an example output using <em>PattenLayout</em> with
  +<p>Here is an example output using <em>PatternLayout</em> with
   the conversion pattern <b>"%r [%t] %-5p %c{2} %x - %m%n"</b>
   
   <pre>
  @@ -245,7 +245,7 @@
   at runtime. Using configuration files the programmer can define
   categories and set their priorities.
   
  -<p>The <code>PropertiesConfigurator</code> defines a particular format
  +<p>The <code>PropertyConfigurator</code> defines a particular format
   of a configuration file. See also the
   <code>org.log4j.examples.Sort</code> example and associated
   configuration files.
  @@ -264,7 +264,7 @@
   debug and info statements?</h4>
   
   <p>For public releases of your code, calling the
  -<codeI>BasicConfigurator.disable(pri)</code> method will disable
  +<code>BasicConfigurator.disable(pri)</code> method will disable
   all messages of priority <code>pri</code> and below.
   
   <p>In cases of problems with an application, technical support can
  @@ -387,7 +387,7 @@
   many benefits:
   
   <ul>
  -  <li>It is very simple to implenent.
  +  <li>It is very simple to implement.
   
     <li>It is very simple to explain to new developpers.
   
  @@ -540,7 +540,7 @@
   
   <p>If your extensions are useful then someone will eventually write an
   extension providing the same or very similar functionality.  Your
  -developement effort will be wasted.
  +development effort will be wasted.
   
   <p>Unless the proprietary log4j extension is business critical, there
   is little reason for not donating your extensions back to the project.
  
  
  
  1.9       +20 -10    jakarta-log4j/doc/HISTORY
  
  Index: HISTORY
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/doc/HISTORY,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- HISTORY	2001/01/22 10:57:24	1.8
  +++ HISTORY	2001/01/23 22:07:24	1.9
  @@ -10,26 +10,36 @@
   
    - Release of version 1.1 (the 21st major release)
   
  + - Logging can now be disabled per Hierarchy. It can also be disabled
  +   using configuration files using the "disable" directive.  The disableOverride 
  +   directive takes precedence over the disable directive.  As a result of this change
  +   the disable family of methods has moved from the BasicConfigurator
  +   class to the Hierarchy class. [**]
  +
  + - Changed the name of the configuration element to log4j:configuration in the
  +   log4j.dtd. All configuration files written in XML need to be
  +   modified. [**]
  +
  +   The following perl command can help:
  +
  +   perl -p -i.bak -e "s/configuration/log4j:configuration/;" file1.xml .. fileN.xml
  +
    - Appenders and Layouts now get to see the raw message object in LoggingEvent 
      not just its rendered form. The access modifiers of some LoggingEvent fields 
      were changed so that they can be accessed in less error-prone ways. Thanks to 
      Jim Cajalic and Anders Kristens for their valuable advice. [*]
  +
  + - The LoggingEvent class now supports serialization of priorities
  +   derived from the org.apache.log4j.Priority class. [*]
    
    - Improved the seach method for searching for the "log4j.properties" file in
      the static initializer of Category class. Thanks to Calvin Chan for
      supplying a better method. [*]
  -
  - - The LoggingEvent class now supports serialization of priorities
  -   derived from the org.apache.log4j.Priority class. [*]
  -
  - - Changed the name of the configuration element to log4j:configuration in the
  -   log4j.dtd. All configuration files written in XML need to be
  -   modified. [**]
   
  -   The following perl command can help:
  + - Added the BufferSize option to the AsyncAppender. [*]
   
  -   perl -p -i.bak -e "s/configuration/log4j:configuration/;" file1.xml .. fileN.xml
  -   
  + - Eliminateed the SecurityExceptions thrown in Applets.  Thanks Timur
  +   Zambalayev for reporting this bug. [*]
   
    - Fixed the errouneously thrown IOInterruptedException when the AsyncAppender 
      was closed. Thanks to Tom Palmer for accurately reporting this bug. [*]
  
  
  
  1.4       +8 -8      jakarta-log4j/doc/deepExtension.html
  
  Index: deepExtension.html
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/doc/deepExtension.html,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- deepExtension.html	2001/01/10 17:50:56	1.3
  +++ deepExtension.html	2001/01/23 22:07:25	1.4
  @@ -113,7 +113,7 @@
   <li>Next <code>info</code> compares the
   <code><a href="../javadoc/org/apache/log4j/Priority.html">Priority</a></code> 
   level for this category against <code>Priority.INFO</code>.  Assuming
  -the priority warrants logging the message, the category instanciates a
  +the priority warrants logging the message, the category instantiates a
   <code><a href="../javadoc/org/apache/log4j/spi/LoggingEvent.html">LoggingEvent</a></code> 
   object populated with information available for logging.
   <p>
  @@ -300,7 +300,7 @@
   Recall from our <a href="#peek">peek under the hood</a> that the
   <code>PatternParser</code> does much of its work in its
   <code>parse</code> method.  The <code>PatternLayout</code> object
  -instanciates a <code>PatternParser</code> object by passing it
  +instantiates a <code>PatternParser</code> object by passing it
   the pattern string.  The PatternLayout then invokes the
   <code>parse</code> method of <code>PatternParser</code> to produce
   a linked list of <code>PatternConverter</code> subclass instances.
  @@ -325,7 +325,7 @@
   <li>constants to identify the various formats
   <li>a converter defined as private static inner-classes of
   	<code>AppServerPatternParser</code>.
  -<li>a <code>finalizeConverter</code> method which instanciates
  +<li>a <code>finalizeConverter</code> method which instantiates
   	the appropriate converter for a given format character.
   </ul>
   <p>
  @@ -335,7 +335,7 @@
   Rather than placing switch logic in the converter, like its
   parent class, each converter only converts one format character.
   This means the decision of which converter subclass
  -to instanciate is made at layout instanciation time rather
  +to instantiate is made at layout instantiation time rather
   than in a switch statement at logging time.
   <p>
   It also differs in that the format constants are characters 
  @@ -469,7 +469,7 @@
   <p>
   <li>Override the <code>forcedLog</code> method to ensure that a 
   	correctly populated instance of 
  -	<code>AppServerLoggingEvent</code> is instanciated rather than
  +	<code>AppServerLoggingEvent</code> is instantiated rather than
   	the default <code>LoggingEvent</code>.
   <p>
   <li>Override the <code>getInstance</code> method to use our
  @@ -492,7 +492,7 @@
   addition to the category name.
   <p>
   The <code>forcedLog</code> method follows closely the corresponding
  -parent class method.  The most important difference is the instanciation
  +parent class method.  The most important difference is the instantiation
   of the <code>AppServerLoggingEvent</code>.  A minor yet necessary 
   difference is the use of the <code>getRendererMap()</code> method rather
   than accessing the data member directory as in <code>Category</code>.
  @@ -589,7 +589,7 @@
   
   The last step is to provide an implementation of the 
   <code>CategoryFactory</code> interface that will correctly 
  -instanciate our <code>AppServerCategory</code> objects.  It
  +instantiate our <code>AppServerCategory</code> objects.  It
   will obtain the hostname of the machine on which it runs using the
   <code>java.net</code> API.  Aside from providing getters and
   setters for the attributes introduced, the only method to
  @@ -707,7 +707,7 @@
   create will not be <code>AppServerCategory</code> instances.  To
   prevent this problem, any <code>AppServerCategory</code> that one
   might want to be configured through a configurator should be
  -instanciated before the configure method is invoked.  In this way,
  +instantiated before the configure method is invoked.  In this way,
   the configurator will configure the <code>AppServerCategory</code>
   that already exists rather than creating an instance of its super
   class in its place.
  
  
  
  1.7       +6 -6      jakarta-log4j/doc/manual.html
  
  Index: manual.html
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/doc/manual.html,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- manual.html	2001/01/18 07:49:39	1.6
  +++ manual.html	2001/01/23 22:07:27	1.7
  @@ -893,13 +893,13 @@
   
   </ol>
   
  -<p>Although log4j has a many features, its first design goal was
  -speed.  Some log4j components have been rewritten many times to
  -improve performance.  Nevertheless, contributors frequently come up
  -with new optimizations. You should be pleased to know that when
  -configured with the <a
  +<p>Although log4j has many features, its first design goal was speed.
  +Some log4j components have been rewritten many times to improve
  +performance.  Nevertheless, contributors frequently come up with new
  +optimizations. You should be pleased to know that when configured with
  +the <a
   href="../javadoc/org/apache/log4j/SimpleLayout.html">SimpleLayout</a>
  -performace tests have shown log4j to log as quickly as
  +performance tests have shown log4j to log as quickly as
   <code>System.out.println</code>.
   
   
  
  
  
  1.8       +39 -6     jakarta-log4j/org/apache/log4j/AsyncAppender.java
  
  Index: AsyncAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/AsyncAppender.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- AsyncAppender.java	2001/01/20 16:02:17	1.7
  +++ AsyncAppender.java	2001/01/23 22:07:35	1.8
  @@ -50,11 +50,27 @@
        <p>Note that all option keys are case sensitive.
     */
     public static final String LOCATION_INFO_OPTION = "LocationInfo";
  -  
  -  static final int BUFFER_SIZE = 128;
  +
  +
  +  /**
  +     A string constant used in naming the option for setting the size of the
  +     internal buffer where logging events are stored until they are written.
  +     Current value of this string constant is <b>BufferSize</b>.  
  +
  +     <p>Note that all option keys are case sensitive.
  +  */
  +  public static final String BUFFER_SIZE_OPTION = "BufferSize";
  +
  +
  +  /**
  +     The default buffer size is set to 128 events.
  +   */
  +  public static final int DEFAULT_BUFFER_SIZE = 128;
  +
     //static Category cat = Category.getInstance(AsyncAppender.class.getName());
  +
  +  BoundedFIFO bf = new BoundedFIFO(DEFAULT_BUFFER_SIZE);
   
  -  BoundedFIFO bf = new BoundedFIFO(BUFFER_SIZE);
     AppenderAttachableImpl aai;
     Dispatcher dispatcher;
     boolean locationInfo = false;
  @@ -170,12 +186,23 @@
   
    
    /**
  -     Set AsyncAppender specific options.
  +     Set AsyncAppender specific options:
   
        <p>On top of the options of the super class {@link
  -     AppenderSkeleton}, the only recognized options is
  -     <b>LocationInfo</b>.
  +     AppenderSkeleton}, the only recognized options are
  +     <b>BufferSize</b> and <b>LocationInfo</b>.
        
  +     <p> The <b>BufferSize</b> option takes a non-negative integer
  +     value.  This integer value determines the maximum size of the
  +     bounded buffer. Increasing the size of the buffer is always
  +     safe. However, if an existing buffer holds unwritten elements,
  +     then <em>decreasing the buffer size will result in event
  +     loss.</em> Nevertheless, while script configuring the
  +     AsyncAppender, it is safe to set a buffer size smaller than the
  +     {@link #DEFAULT_BUFFER_SIZE default buffer size} because
  +     configurators guarantee that an appender cannot be used before
  +     being completely configured. 
  +
        <p>The <b>LocationInfo</b> option takes a boolean value. By
        default, it is set to false which means there will be no effort
        to extract the location information related to the event. As a
  @@ -194,6 +221,12 @@
   
       if (option.equals(LOCATION_INFO_OPTION))
         locationInfo = OptionConverter.toBoolean(value, locationInfo);
  +    else if (option.equals(BUFFER_SIZE_OPTION)) {
  +      int newSize = OptionConverter.toInt(value, DEFAULT_BUFFER_SIZE);
  +      bf.resize(newSize);
  +    }
  +    
  +
     }
   
   }
  
  
  
  1.3       +47 -3     jakarta-log4j/org/apache/log4j/helpers/BoundedFIFO.java
  
  Index: BoundedFIFO.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/helpers/BoundedFIFO.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BoundedFIFO.java	2000/12/14 21:07:43	1.2
  +++ BoundedFIFO.java	2001/01/23 22:07:39	1.3
  @@ -55,9 +55,8 @@
   
     /**
        Place a {@link LoggingEvent} in the buffer. If the buffer is full
  -     then the event is silently dropped. It is the caller's
  -     responsability to make sure that the buffer has free space.
  -  */
  +     then the event is <b>silently dropped</b>. It is the caller's
  +     responsability to make sure that the buffer has free space.  */
     public 
     void put(LoggingEvent o) {
       if(numElements != maxSize) {      
  @@ -95,6 +94,51 @@
       return numElements;
     } 
   
  +
  +  int min(int a, int b) {
  +    return a < b ? a : b;
  +  }
  +
  +  synchronized
  +  public 
  +  void resize(int newSize) {
  +    if(newSize == maxSize) 
  +      return;
  +
  +
  +   LoggingEvent[] tmp = new LoggingEvent[newSize];
  +
  +   // we should not copy beyond the buf array
  +   int len1 = maxSize - first;
  +
  +   // we should not copy beyond the tmp array
  +   len1 = min(len1, newSize);
  +
  +   // er.. how much do we actually need to copy?
  +   // We should not copy more than the actual number of elements.
  +   len1 = min(len1, numElements);
  +
  +   // Copy from buf starting a first, to tmp, starting at position 0, len1 elements.
  +   System.arraycopy(buf, first, tmp, 0, len1);
  +   
  +   // Are there remain uncopied elements and there is still space in the new array?
  +   int len2 = 0;
  +   if((len1 < numElements) && (len1 < newSize)) {
  +     len2 = numElements - len1;
  +     len2 = min(len2, newSize - len1);
  +     System.arraycopy(buf, 0, tmp, len1, len2);
  +   }
  +   
  +   this.buf = tmp;
  +   this.maxSize = newSize;    
  +   this.first=0;   
  +   this.numElements = len1+len2;
  +   this.next = this.numElements;
  +   if(this.next == this.maxSize) 
  +     this.next = 0;
  +  }
  +
  +  
     /**
        Returns <code>true</code> if there is just one element in the
        buffer. In other words, if there were no elements before the last
  
  
  
  1.3       +115 -1    jakarta-log4j/org/apache/log4j/test/UnitTestBoundedFIFO.java
  
  Index: UnitTestBoundedFIFO.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/test/UnitTestBoundedFIFO.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- UnitTestBoundedFIFO.java	2000/12/14 21:08:14	1.2
  +++ UnitTestBoundedFIFO.java	2001/01/23 22:07:42	1.3
  @@ -90,7 +90,7 @@
   	    assertEquals(r, e[k]);
   	}
         }
  -      System.out.println("Passed size="+size);
  +      //System.out.println("Passed size="+size);
       }
     }
   
  @@ -115,7 +115,118 @@
       assertEquals(bf.get(), e[3]); assertEquals(bf.length(), 0);
       assertNull(bf.get()); assertEquals(bf.length(), 0);
     }
  +
  +  int min(int a, int b) {
  +    return a < b ? a : b;
  +  }
  +  
  +
  +  /**
  +     Pattern ++++++++++++++++++++ (insert only);
  +   */
  +  public
  +  void testResize1() {
  +    int size = 10;
  +
  +    for(int n = 1; n < size*2; n++) {
  +      for(int i = 0; i < size*2; i++) {
  +
  +        BoundedFIFO bf = new BoundedFIFO(size);
  +        for(int f = 0; f < i; f++) {
  +          bf.put(e[f]);
  +        }
  +
  +        bf.resize(n);
  +        int expectedSize = min(n, min(i, size));
  +        assertEquals(bf.length(), expectedSize);
  +        for(int c = 0; c < expectedSize; c++) {
  +          assertEquals(bf.get(), e[c]);
  +        }
  +      }
  +    }
  +  }
  +
  +
     
  +  /**
  +     Pattern ++...+ --...-
  +   */
  +  public
  +  void testResize2() {
  +    int size = 10;
  +
  +    for(int n = 1; n < size*2; n++) {
  +      for(int i = 0; i < size*2; i++) {
  +	for(int d = 0; d < min(i,size); d++) {
  +	  
  +	  BoundedFIFO bf = new BoundedFIFO(size);
  +	  for(int p = 0; p < i; p++) {
  +	    bf.put(e[p]);
  +	  }
  +
  +	  for(int g = 0; g < d; g++) {
  +	    bf.get();
  +	  }
  +
  +	  // x = the number of elems in 
  +	  int x = bf.length();
  +
  +	  bf.resize(n);
  +
  +	  int expectedSize = min(n, x);
  +	  assertEquals(bf.length(), expectedSize);
  +
  +	  for(int c = 0; c < expectedSize; c++) {
  +	    assertEquals(bf.get(), e[c+d]);
  +	  }
  +	  assertNull(bf.get());
  +	}
  +      }
  +    }
  +  }
  +
  +
  +  /**
  +     Pattern: i inserts, d deletes, r inserts
  +   */
  +  public
  +  void testResize3() {
  +    int size = 10;
  +
  +    for(int n = 1; n < size*2; n++) {
  +      for(int i = 0; i < size; i++) {
  +	for(int d = 0; d < i; d++) {
  +	  for(int r = 0; r < d; r++) {
  +	  
  +	    BoundedFIFO bf = new BoundedFIFO(size);
  +	    for(int p0 = 0; p0 < i; p0++)
  +	      bf.put(e[p0]);
  +
  +	    for(int g = 0; g < d; g++) 
  +	      bf.get();	    
  +	    for(int p1 = 0; p1 < r; p1++) 
  +	      bf.put(e[i+p1]);
  +	    
  +
  +	    
  +	    int x =  bf.length();
  +
  +	    bf.resize(n);
  +	    
  +
  +	    int expectedSize = min(n, x);
  +	    assertEquals(bf.length(), expectedSize);
  +
  +	    for(int c = 0; c < expectedSize; c++) {
  +	      assertEquals(bf.get(), e[c+d]);
  +	    }
  +	    //assertNull(bf.get());
  +	  }
  +	}
  +      }
  +    }
  +  }
  +
   
     public
     static
  @@ -123,6 +234,9 @@
       TestSuite suite = new TestSuite();
       suite.addTest(new UnitTestBoundedFIFO("test1"));
       suite.addTest(new UnitTestBoundedFIFO("test2"));
  +    suite.addTest(new UnitTestBoundedFIFO("testResize1"));
  +    suite.addTest(new UnitTestBoundedFIFO("testResize2"));
  +    suite.addTest(new UnitTestBoundedFIFO("testResize3"));
       return suite;
     }
   }
  
  
  
  1.5       +6 -0      jakarta-log4j/org/apache/log4j/test/unitTest
  
  Index: unitTest
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/org/apache/log4j/test/unitTest,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- unitTest	2001/01/05 21:09:11	1.4
  +++ unitTest	2001/01/23 22:07:43	1.5
  @@ -21,6 +21,12 @@
     exit 1   
   fi
   
  +java junit.textui.TestRunner org.apache.log4j.test.UnitTestBoundedFIFO
  +if [ $? != 0 ]; then
  +  echo "UnitUnitTestBoundedFIFO failed."
  +  exit 1   
  +fi
  +
   java junit.textui.TestRunner org.apache.log4j.test.UnitTestOR
   if [ $? != 0 ]; then
     echo "UnitTestOR failed."