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 2002/05/09 17:43:44 UTC

cvs commit: jakarta-log4j/tests/src/java/org/apache/log4j/util Compare.java

ceki        02/05/09 08:43:44

  Modified:    docs     HISTORY
               src/java/org/apache/log4j AsyncAppender.java Hierarchy.java
                        Priority.java
               src/java/org/apache/log4j/chainsaw LoggingReceiver.java
               src/java/org/apache/log4j/helpers OptionConverter.java
               src/java/org/apache/log4j/net SocketHubAppender.java
               src/java/org/apache/log4j/performance logging
               src/java/org/apache/log4j/spi LoggingEvent.java
               src/java/org/apache/log4j/varia FallbackErrorHandler.java
                        LevelMatchFilter.java
               src/java/org/apache/log4j/xml log4j.dtd
               src/xdocs contactUs.xml
               tests/src/java/org/apache/log4j/helpers
                        OptionConverterTestCase.java
               tests/src/java/org/apache/log4j/util Compare.java
  Log:
  Added support for resursive variable substitution in OptionConverter.java.
  
  Minor changes so that more of log4j compiles under JDK 1.1. Changes mostly
  related to the method in the Vector class.
  
  Cosmetic changes in chainsaw/LoggingReceiver.java
  
  Minor documentation changes and new comments in source code.
  
  Revision  Changes    Path
  1.94      +15 -0     jakarta-log4j/docs/HISTORY
  
  Index: HISTORY
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/docs/HISTORY,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- HISTORY	30 Apr 2002 15:56:34 -0000	1.93
  +++ HISTORY	9 May 2002 15:43:43 -0000	1.94
  @@ -9,6 +9,21 @@
    
    - Release of version 1.2 
   
  + - Added support for recursive variable substiuton as requested by
  +   Eric Chastan. [*]
  +
  + - SocketNode now used a BufferedInputStream as suggested by Kok Chong
  +   in bug report #3933. [*]
  +
  + - Fixed a problem with DailiyRollingAppender which would not
  +   correctly compute the rollover period in certain timezones. See bug
  +   report #7550. [*]
  +
  + - Fixed documentation bug #2726 in FAQ.html. [*]
  +
  + - In WriterAppender, fixed bug #2383 by adding a flush statement in the
  +   writeFooter method. [*]
  +   
    - In XMLLayout, Fixed bug #7550 by escaping the method attribute. The 
      XMLLayout also outputs each item of a stack trace in a separate
      line. [*]
  
  
  
  1.29      +1 -1      jakarta-log4j/src/java/org/apache/log4j/AsyncAppender.java
  
  Index: AsyncAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/AsyncAppender.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- AsyncAppender.java	25 Apr 2002 22:22:07 -0000	1.28
  +++ AsyncAppender.java	9 May 2002 15:43:43 -0000	1.29
  @@ -87,7 +87,7 @@
     public
     AsyncAppender() {
       // Note: The dispatcher code assumes that the aai is set once and
  -    // for all!!!
  +    // for all.
       aai = new AppenderAttachableImpl();
       dispatcher = new Dispatcher(bf, this);
       dispatcher.start();
  
  
  
  1.40      +1 -1      jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java
  
  Index: Hierarchy.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Hierarchy.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- Hierarchy.java	24 Apr 2002 01:16:14 -0000	1.39
  +++ Hierarchy.java	9 May 2002 15:43:43 -0000	1.40
  @@ -98,7 +98,7 @@
       if(listeners.contains(listener)) {
         LogLog.warn("Ignoring attempt to add an existent listener.");
       } else {
  -      listeners.add(listener);
  +      listeners.addElement(listener);
       }
     }
   
  
  
  
  1.23      +0 -2      jakarta-log4j/src/java/org/apache/log4j/Priority.java
  
  Index: Priority.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/Priority.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- Priority.java	22 Feb 2002 18:36:28 -0000	1.22
  +++ Priority.java	9 May 2002 15:43:43 -0000	1.23
  @@ -185,6 +185,4 @@
     Priority toPriority(String sArg, Priority defaultPriority) {                  
       return Level.toLevel(sArg, (Level) defaultPriority);
     }
  -
  -
   }
  
  
  
  1.2       +15 -22    jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java
  
  Index: LoggingReceiver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LoggingReceiver.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LoggingReceiver.java	23 Mar 2002 07:51:26 -0000	1.1
  +++ LoggingReceiver.java	9 May 2002 15:43:43 -0000	1.2
  @@ -12,7 +12,7 @@
   import java.net.ServerSocket;
   import java.net.Socket;
   import java.net.SocketException;
  -import org.apache.log4j.Category;
  +import org.apache.log4j.Logger;
   import org.apache.log4j.spi.LoggingEvent;
   
   /**
  @@ -21,12 +21,9 @@
    *
    * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
    */
  -class LoggingReceiver
  -    extends Thread
  -{
  +class LoggingReceiver extends Thread {
       /** used to log messages **/
  -    private static final Category LOG =
  -        Category.getInstance(LoggingReceiver.class);
  +    private static final Logger logger = Logger.getLogger(LoggingReceiver.class);
   
       /**
        * Helper that actually processes a client connection. It receives events
  @@ -34,9 +31,7 @@
        *
        * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
        */
  -    private class Slurper
  -        implements Runnable
  -    {
  +    private class Slurper implements Runnable {
           /** socket connection to read events from **/
           private final Socket mClient;
   
  @@ -51,7 +46,7 @@
   
           /** loops getting the events **/
           public void run() {
  -            LOG.debug("Starting to get data");
  +            logger.debug("Starting to get data");
               try {
                   final ObjectInputStream ois =
                       new ObjectInputStream(mClient.getInputStream());
  @@ -60,19 +55,19 @@
                       mModel.addEvent(new EventDetails(event));
                   }
               } catch (EOFException e) {
  -                LOG.info("Reached EOF, closing connection");
  +                logger.info("Reached EOF, closing connection");
               } catch (SocketException e) {
  -                LOG.info("Caught SocketException, closing connection");
  +                logger.info("Caught SocketException, closing connection");
               } catch (IOException e) {
  -                LOG.warn("Got IOException, closing connection", e);
  +                logger.warn("Got IOException, closing connection", e);
               } catch (ClassNotFoundException e) {
  -                LOG.warn("Got ClassNotFoundException, closing connection", e);
  +                logger.warn("Got ClassNotFoundException, closing connection", e);
               }
   
               try {
                   mClient.close();
               } catch (IOException e) {
  -                LOG.warn("Error closing connection", e);
  +                logger.warn("Error closing connection", e);
               }
           }
       }
  @@ -90,9 +85,7 @@
        * @param aPort port to listen on
        * @throws IOException if an error occurs
        */
  -    LoggingReceiver(MyTableModel aModel, int aPort)
  -        throws IOException
  -    {
  +    LoggingReceiver(MyTableModel aModel, int aPort) throws IOException {
           setDaemon(true);
           mModel = aModel;
           mSvrSock = new ServerSocket(aPort);
  @@ -100,19 +93,19 @@
   
       /** Listens for client connections **/
       public void run() {
  -        LOG.info("Thread started");
  +        logger.info("Thread started");
           try {
               while (true) {
  -                LOG.debug("Waiting for a connection");
  +                logger.debug("Waiting for a connection");
                   final Socket client = mSvrSock.accept();
  -                LOG.debug("Got a connection from " +
  +                logger.debug("Got a connection from " +
                             client.getInetAddress().getHostName());
                   final Thread t = new Thread(new Slurper(client));
                   t.setDaemon(true);
                   t.start();
               }
           } catch (IOException e) {
  -            LOG.error("Error in accepting connections, stopping.", e);
  +            logger.error("Error in accepting connections, stopping.", e);
           }
       }
   }
  
  
  
  1.36      +17 -13    jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java
  
  Index: OptionConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/helpers/OptionConverter.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- OptionConverter.java	24 Apr 2002 15:11:50 -0000	1.35
  +++ OptionConverter.java	9 May 2002 15:43:43 -0000	1.36
  @@ -33,8 +33,6 @@
     static int DELIM_START_LEN = 2;
     static int DELIM_STOP_LEN  = 1;
   
  -  static StringBuffer sbuf = new StringBuffer();
  -
     /** OptionConverter is a static class. */
     private OptionConverter() {}
   
  @@ -315,8 +313,7 @@
   	  return defaultValue;
   	}
   	return classObj.newInstance();
  -      }
  -      catch (Exception e) {
  +      } catch (Exception e) {
   	LogLog.error("Could not instantiate class [" + className + "].", e);
         }
       }
  @@ -363,7 +360,8 @@
     public static
     String substVars(String val, Properties props) throws
                           IllegalArgumentException {
  -    sbuf.setLength(0);
  +
  +    StringBuffer sbuf = new StringBuffer();
   
       int i = 0;
       int j, k;
  @@ -371,22 +369,21 @@
       while(true) {
         j=val.indexOf(DELIM_START, i);
         if(j == -1) {
  -	if(i==0)
  +	// no more variables
  +	if(i==0) { // this is a simple string
   	  return val;
  -	else {
  +	} else { // add the tail string which contails no variables and return the result.
   	  sbuf.append(val.substring(i, val.length()));
   	  return sbuf.toString();
   	}
  -      }
  -      else {
  +      } else {
   	sbuf.append(val.substring(i, j));
   	k = val.indexOf(DELIM_STOP, j);
   	if(k == -1) {
   	  throw new IllegalArgumentException('"'+val+
   		      "\" has no closing brace. Opening brace at position " + j
   					     + '.');
  -	}
  -	else {
  +	} else {
   	  j += DELIM_START_LEN;
   	  String key = val.substring(j, k);
   	  // first try in System properties
  @@ -396,8 +393,15 @@
   	    replacement =  props.getProperty(key);
   	  }
   
  -	  if(replacement != null)
  -	    sbuf.append(replacement);
  +	  if(replacement != null) {
  +	    // Do variable substitution on the replacement string
  +	    // such that we can solve "Hello ${x2}" as "Hello p1" 
  +            // the where the properties are
  +	    // x1=p1
  +            // x2=${x1}
  +	    String recursiveReplacement = substVars(replacement, props);
  +	    sbuf.append(recursiveReplacement);
  +	  }
   	  i = k + DELIM_STOP_LEN;
   	}
         }
  
  
  
  1.4       +5 -5      jakarta-log4j/src/java/org/apache/log4j/net/SocketHubAppender.java
  
  Index: SocketHubAppender.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/net/SocketHubAppender.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SocketHubAppender.java	4 Apr 2002 14:46:02 -0000	1.3
  +++ SocketHubAppender.java	9 May 2002 15:43:44 -0000	1.4
  @@ -151,7 +151,7 @@
       // close all of the connections
   	LogLog.debug("closing client connections");
       while (oosList.size() != 0) {
  -      ObjectOutputStream oos = (ObjectOutputStream)oosList.get(0);
  +      ObjectOutputStream oos = (ObjectOutputStream)oosList.elementAt(0);
         if(oos != null) {
           try {
           	oos.close();
  @@ -160,7 +160,7 @@
           	LogLog.error("could not close oos.", e);
           }
           
  -        oosList.remove(0);     
  +        oosList.removeElementAt(0);     
         }
       }
     }
  @@ -183,7 +183,7 @@
   
         ObjectOutputStream oos = null;
         try {
  -        oos = (ObjectOutputStream)oosList.get(streamCount);
  +        oos = (ObjectOutputStream)oosList.elementAt(streamCount);
         }
         catch (ArrayIndexOutOfBoundsException e) {
           // catch this, but just don't assign a value
  @@ -205,7 +205,7 @@
         }
         catch(IOException e) {
         	// there was an io exception so just drop the connection
  -      	oosList.remove(streamCount);
  +      	oosList.removeElementAt(streamCount);
         	LogLog.debug("dropped connection");
         	
         	// decrement to keep the counter in place (for loop always increments)
  @@ -357,7 +357,7 @@
                 ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
   	            
                 // add it to the oosList.  OK since Vector is synchronized.
  -              oosList.add(oos);
  +              oosList.addElement(oos);
               }
               catch (IOException e) {
                 LogLog.error("exception creating output stream on socket.", e);
  
  
  
  1.3       +3 -1      jakarta-log4j/src/java/org/apache/log4j/performance/logging
  
  Index: logging
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/performance/logging,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- logging	26 Dec 2000 23:39:08 -0000	1.2
  +++ logging	9 May 2002 15:43:44 -0000	1.3
  @@ -306,8 +306,10 @@
   #  Remote logging
   # ===============================================================
   TEST=1000
  +#RL=1000
  +RL=20000
   if [ $TEST -ge $start ]; then
  -   java org.apache.log4j.performance.Logging xml/logging$TEST.xml 10000 100 100
  +   java org.apache.log4j.performance.Logging xml/logging$TEST.xml $RL 100 100
      #multiRun 4 "SocketAppender" $SHORTRUN $DELAY
   fi
   
  
  
  
  1.30      +6 -0      jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java
  
  Index: LoggingEvent.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- LoggingEvent.java	30 Apr 2002 15:56:34 -0000	1.29
  +++ LoggingEvent.java	9 May 2002 15:43:44 -0000	1.30
  @@ -308,6 +308,12 @@
   	Method m = (Method) methodCache.get(className);
   	if(m == null) {
   	  Class clazz = Class.forName(className);
  +	  // Note that we use Class.getDeclaredMethod instead of
  +	  // Class.getMethod. This assumes that the Level subclass
  +	  // implements the toLevel(int) method which is a
  +	  // requirement. Actually, it does not make sense for Level
  +	  // subclasses NOT to implement this method. Also note that
  +	  // only Level can be subclassed and not Priority.
   	  m = clazz.getDeclaredMethod(TO_LEVEL, TO_LEVEL_PARAMS);
   	  methodCache.put(className, m);
   	}
  
  
  
  1.5       +2 -2      jakarta-log4j/src/java/org/apache/log4j/varia/FallbackErrorHandler.java
  
  Index: FallbackErrorHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/varia/FallbackErrorHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- FallbackErrorHandler.java	18 Feb 2002 16:29:44 -0000	1.4
  +++ FallbackErrorHandler.java	9 May 2002 15:43:44 -0000	1.5
  @@ -47,7 +47,7 @@
       if(loggers == null) {
         loggers = new Vector();
       }
  -    loggers.add(logger);
  +    loggers.addElement(logger);
     }
   
   
  @@ -74,7 +74,7 @@
     public
     void error(String message, Exception e, int errorCode, LoggingEvent event) {
       for(int i = 0; i < loggers.size(); i++) {
  -      Logger l = (Logger) loggers.get(i);
  +      Logger l = (Logger) loggers.elementAt(i);
         LogLog.debug("FB: Searching for ["+primary.getName()+"] in logger"
   		   +l.getName());
         //if(l.isAttached(primary)) {
  
  
  
  1.5       +2 -4      jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java
  
  Index: LevelMatchFilter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/varia/LevelMatchFilter.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LevelMatchFilter.java	25 Apr 2002 22:22:07 -0000	1.4
  +++ LevelMatchFilter.java	9 May 2002 15:43:44 -0000	1.5
  @@ -16,10 +16,9 @@
   /**
      This is a very simple filter based on level matching.
   
  -
      <p>The filter admits two options <b>LevelToMatch</b> and
      <b>AcceptOnMatch</b>. If there is an exact match between the value
  -   of the LevelToMatch option and the level of the {@link
  +   of the <b>LevelToMatch</b> option and the level of the {@link
      LoggingEvent}, then the {@link #decide} method returns {@link
      Filter#ACCEPT} in case the <b>AcceptOnMatch</b> option value is set
      to <code>true</code>, if it is <code>false</code> then {@link
  @@ -28,8 +27,7 @@
   
      @author Ceki G&uuml;lc&uuml;
   
  -   @since 1.2
  -*/
  +   @since 1.2 */
   public class LevelMatchFilter extends Filter {
     
     /**
  
  
  
  1.18      +1 -0      jakarta-log4j/src/java/org/apache/log4j/xml/log4j.dtd
  
  Index: log4j.dtd
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/xml/log4j.dtd,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- log4j.dtd	26 Apr 2002 16:11:42 -0000	1.17
  +++ log4j.dtd	9 May 2002 15:43:44 -0000	1.18
  @@ -131,6 +131,7 @@
   <!-- ==================================================================== -->
   <!ELEMENT log4j:eventSet (log4j:event*)>
   <!ATTLIST log4j:eventSet
  +  xmlns:log4j             CDATA #FIXED "http://jakarta.apache.org/log4j/" 
     version                (1.1|1.2) "1.2" 
     includesLocationInfo   (true|false) "true"
   >
  
  
  
  1.14      +4 -3      jakarta-log4j/src/xdocs/contactUs.xml
  
  Index: contactUs.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/xdocs/contactUs.xml,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- contactUs.xml	30 Apr 2002 15:56:34 -0000	1.13
  +++ contactUs.xml	9 May 2002 15:43:44 -0000	1.14
  @@ -77,9 +77,10 @@
   	the database</a> and the <a href="HISTORY">project history
   	file</a> to see if the problem is not already known. Before
   	filing a report, you should first send email to the
  -	<em>log4j-user</em> mailing list describing the bug. Only
  -	after these precautionary steps should you file a bug report
  -	with Bugzilla.
  +	<em>log4j-user</em> mailing list describing the bug ensuring
  +	that you are not filing an already known problem. Only after
  +	these precautionary steps should you file a bug report with
  +	Bugzilla.
         </p>
   
         <p>Although Bugzilla allows users to file enhancement requests
  
  
  
  1.2       +15 -1     jakarta-log4j/tests/src/java/org/apache/log4j/helpers/OptionConverterTestCase.java
  
  Index: OptionConverterTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/helpers/OptionConverterTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- OptionConverterTestCase.java	18 Feb 2002 17:36:37 -0000	1.1
  +++ OptionConverterTestCase.java	9 May 2002 15:43:44 -0000	1.2
  @@ -83,10 +83,22 @@
       catch(IllegalArgumentException e) {
         String errorMsg = e.getMessage();
         //System.out.println('['+errorMsg+']');
  -      assertEquals('"'+val+ "\" has no closing brace. Opening brace at position 6.", errorMsg);
  +      assertEquals('"'+val
  +		   + "\" has no closing brace. Opening brace at position 6.", 
  +		   errorMsg);
       }
     }
   
  +  public
  +  void varSubstTest5() {
  +    System.out.println("-----------------------------------------");
  +    Properties props = new Properties();
  +    props.put("p1", "x1");
  +    props.put("p2", "${p1}");
  +    String res = OptionConverter.substVars("${p2}", props);
  +    System.out.println("Result is ["+res+"].");
  +    assertEquals(res, "x1");
  +  }
   
     public
     void toLevelTest1() {
  @@ -128,10 +140,12 @@
     static
     Test suite() {
       TestSuite suite = new TestSuite();
  +    suite.addTest(new OptionConverterTestCase("varSubstTest5"));
       suite.addTest(new OptionConverterTestCase("varSubstTest1"));
       suite.addTest(new OptionConverterTestCase("varSubstTest2"));
       suite.addTest(new OptionConverterTestCase("varSubstTest3"));
       suite.addTest(new OptionConverterTestCase("varSubstTest4"));
  +
   
       suite.addTest(new OptionConverterTestCase("toLevelTest1"));
       suite.addTest(new OptionConverterTestCase("toLevelTest2"));
  
  
  
  1.5       +1 -1      jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java
  
  Index: Compare.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/tests/src/java/org/apache/log4j/util/Compare.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Compare.java	29 Apr 2002 14:41:23 -0000	1.4
  +++ Compare.java	9 May 2002 15:43:44 -0000	1.5
  @@ -34,7 +34,7 @@
         if(!s1.equals(s2)) {
   	System.out.println("Files ["+file1+"] and ["+file2+"] differ on line " 
   			   +lineCounter);
  -	System.out.println("One  reads: ["+s1+"].");
  +	System.out.println("One reads:  ["+s1+"].");
   	System.out.println("Other reads:["+s2+"].");
   	return false;
         }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>