You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by sd...@apache.org on 2004/06/20 09:28:53 UTC

cvs commit: logging-log4j/src/java/org/apache/log4j/chainsaw/help tutorial.html release-notes.html

sdeboy      2004/06/20 00:28:53

  Modified:    src/java/org/apache/log4j/helpers Constants.java
               src/java/org/apache/log4j/chainsaw LogPanel.java
               src/java/org/apache/log4j/rule InequalityRule.java
                        EqualsRule.java
               src/java/org/apache/log4j/chainsaw/help tutorial.html
                        release-notes.html
  Added:       src/java/org/apache/log4j/rule TimestampEqualsRule.java
                        TimestampInequalityRule.java
  Log:
  Expression rule enhancements:
  * Added support for evaluating the Timestamp field using the pattern 'yyyy/MM/dd HH:mm:ss' (ticks required).  Milliseconds are ignored (rounded down) during the evaluation of events.  This is true for inequality and equality evaluations.
  * Expression rule enhancement:  Level equality evaluations are now case-insensitive.
  
  Revision  Changes    Path
  1.6       +1 -0      logging-log4j/src/java/org/apache/log4j/helpers/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/helpers/Constants.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Constants.java	21 May 2004 18:45:07 -0000	1.5
  +++ Constants.java	20 Jun 2004 07:28:52 -0000	1.6
  @@ -24,6 +24,7 @@
     static final String APPLICATION_KEY = "application";
     static final String HOSTNAME_KEY = "hostname";
     static final String LOG4J_ID_KEY = "log4jid";
  +  public static final String TIMESTAMP_RULE_FORMAT = "yyyy/MM/dd HH:mm:ss";
   
     /*
      * The default property file name for automatic configuration.
  
  
  
  1.76      +5 -6      logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
  
  Index: LogPanel.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- LogPanel.java	27 May 2004 07:50:58 -0000	1.75
  +++ LogPanel.java	20 Jun 2004 07:28:53 -0000	1.76
  @@ -50,9 +50,11 @@
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
   import java.io.Serializable;
  +import java.text.DateFormat;
   import java.text.NumberFormat;
   import java.text.SimpleDateFormat;
   import java.util.ArrayList;
  +import java.util.Date;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.HashSet;
  @@ -119,6 +121,7 @@
   import org.apache.log4j.chainsaw.prefs.Profileable;
   import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SettingsManager;
  +import org.apache.log4j.helpers.Constants;
   import org.apache.log4j.helpers.ISO8601DateFormat;
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.rule.ExpressionRule;
  @@ -224,6 +227,7 @@
     static final String COLUMNS_EXTENSION = ".columns";
     static final String COLORS_EXTENSION = ".colors";
     private int previousLastIndex = -1;
  +  private final DateFormat timestampExpressionFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT); 
   
     /**
      * Creates a new LogPanel object.  If a LogPanel with this identifier has
  @@ -1153,12 +1157,7 @@
               String value = "";
   
               if (colName.equalsIgnoreCase(ChainsawConstants.TIMESTAMP_COL_NAME)) {
  -              JComponent comp =
  -                (JComponent) table.getCellRenderer(row, column);
  -
  -              if (comp instanceof JLabel) {
  -                value = ((JLabel) comp).getText();
  -              }
  +            	value = timestampExpressionFormat.format(new Date(table.getValueAt(row, column).toString()));
               } else {
                 Object o = table.getValueAt(row, column);
   
  
  
  
  1.6       +3 -2      logging-log4j/src/java/org/apache/log4j/rule/InequalityRule.java
  
  Index: InequalityRule.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/InequalityRule.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InequalityRule.java	25 Mar 2004 03:39:24 -0000	1.5
  +++ InequalityRule.java	20 Jun 2004 07:28:53 -0000	1.6
  @@ -30,7 +30,6 @@
    * @author Scott Deboy <sd...@apache.org>
    */
   public class InequalityRule extends AbstractRule {
  -  private static final String LEVEL = "LEVEL";
     private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
     private final String field;
     private final String value;
  @@ -58,9 +57,11 @@
     }
     
     public static Rule getRule(String inequalitySymbol, String field, String value) {
  -    if (field.equalsIgnoreCase(LEVEL)) {
  +    if (field.equalsIgnoreCase(LoggingEventFieldResolver.LEVEL_FIELD)) {
         //push the value back on the stack and allow the level-specific rule pop values
         return LevelInequalityRule.getRule(inequalitySymbol, value);
  +    } else if (field.equalsIgnoreCase(LoggingEventFieldResolver.TIMESTAMP_FIELD)){
  +      return TimestampInequalityRule.getRule(inequalitySymbol, value);
       } else {
         return new InequalityRule(inequalitySymbol, field, value);
       }
  
  
  
  1.6       +8 -2      logging-log4j/src/java/org/apache/log4j/rule/EqualsRule.java
  
  Index: EqualsRule.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/EqualsRule.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EqualsRule.java	25 Mar 2004 03:39:24 -0000	1.5
  +++ EqualsRule.java	20 Jun 2004 07:28:53 -0000	1.6
  @@ -53,11 +53,17 @@
       String p2 = stack.pop().toString();
       String p1 = stack.pop().toString();
   
  -    return new EqualsRule(p1, p2);
  +    return getRule(p1, p2);
     }
   
     public static Rule getRule(String p1, String p2) {
  -    return new EqualsRule(p1, p2);
  +    if (p1.equalsIgnoreCase(LoggingEventFieldResolver.LEVEL_FIELD)) {
  +    	return PartialTextMatchRule.getRule(p1, p2);
  +    } else if (p1.equalsIgnoreCase(LoggingEventFieldResolver.TIMESTAMP_FIELD)) {
  +    	return TimestampEqualsRule.getRule(p2);
  +    }else {
  +    	return new EqualsRule(p1, p2);
  +    }
     }
   
     public boolean evaluate(LoggingEvent event) {
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/rule/TimestampEqualsRule.java
  
  Index: TimestampEqualsRule.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.rule;
  
  import java.io.IOException;
  import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  
  import org.apache.log4j.helpers.Constants;
  import org.apache.log4j.spi.LoggingEvent;
  import org.apache.log4j.spi.LoggingEventFieldResolver;
  
  /**
   * A Rule class implementing inequality evaluation for Levels (log4j and util.logging) using the toInt method.
   * 
   * @author Scott Deboy <sd...@apache.org>
   */
  public class TimestampEqualsRule extends AbstractRule {
  
    private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
    private static final DateFormat dateFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
    private long timeStamp;
    
    private TimestampEqualsRule(String value) {
    	//expects value to be a timestamp value represented as a long
      try {
      	timeStamp = dateFormat.parse(value).getTime();
      } catch (ParseException pe) {
      	throw new IllegalArgumentException("Could not parse date: " + value);
      }
    } 
  
    public static Rule getRule(String value) {
        return new TimestampEqualsRule(value);
    }
    
    public boolean evaluate(LoggingEvent event) {
      long eventTimeStamp = Long.parseLong(resolver.getValue("TIMESTAMP", event).toString()) / 1000 * 1000; 
  	return eventTimeStamp == timeStamp;
    }
    
    /**
      * Deserialize the state of the object
      *
      * @param in 
      *
      * @throws IOException 
      * @throws ClassNotFoundException 
      */
     private void readObject(java.io.ObjectInputStream in)
       throws IOException, ClassNotFoundException {
       timeStamp = in.readLong(); 
     }
  
     /**
      * Serialize the state of the object
      *
      * @param out 
      *
      * @throws IOException 
      */
     private void writeObject(java.io.ObjectOutputStream out)
       throws IOException {
       out.writeLong(timeStamp);
     }
  }
  
  
  
  1.1                  logging-log4j/src/java/org/apache/log4j/rule/TimestampInequalityRule.java
  
  Index: TimestampInequalityRule.java
  ===================================================================
  /*
   * Copyright 1999,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  package org.apache.log4j.rule;
  
  import java.io.IOException;
  import java.text.DateFormat;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  
  import org.apache.log4j.helpers.Constants;
  import org.apache.log4j.spi.LoggingEvent;
  import org.apache.log4j.spi.LoggingEventFieldResolver;
  
  /**
   * A Rule class implementing inequality evaluation for Levels (log4j and util.logging) using the toInt method.
   * 
   * @author Scott Deboy <sd...@apache.org>
   */
  public class TimestampInequalityRule extends AbstractRule {
  
    private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
    private static final DateFormat dateFormat = new SimpleDateFormat(Constants.TIMESTAMP_RULE_FORMAT);
    private transient String inequalitySymbol;
    private long timeStamp;
    
    private TimestampInequalityRule(
      String inequalitySymbol, String value) {
  
      this.inequalitySymbol = inequalitySymbol;
      try {
      	timeStamp = dateFormat.parse(value).getTime();
      } catch (ParseException pe) {
      	throw new IllegalArgumentException("Could not parse date: " + value);
      }
    } 
  
    public static Rule getRule(String inequalitySymbol, String value) {
        return new TimestampInequalityRule(inequalitySymbol, value);
    }
    
    public boolean evaluate(LoggingEvent event) {
      long eventTimeStamp = Long.parseLong(resolver.getValue("TIMESTAMP", event).toString()) / 1000 * 1000; 
      boolean result = false;
      long first = eventTimeStamp;
      long second = timeStamp;
  
      if ("<".equals(inequalitySymbol)) {
        result = first < second;
      } else if (">".equals(inequalitySymbol)) {
        result = first > second;
      } else if ("<=".equals(inequalitySymbol)) {
        result = first <= second;
      } else if (">=".equals(inequalitySymbol)) {
        result = first >= second;
      }
  
      return result;
    }
    
    /**
      * Deserialize the state of the object
      *
      * @param in 
      *
      * @throws IOException 
      * @throws ClassNotFoundException 
      */
     private void readObject(java.io.ObjectInputStream in)
       throws IOException, ClassNotFoundException {
       inequalitySymbol = (String)in.readObject();
       timeStamp = in.readLong(); 
     }
  
     /**
      * Serialize the state of the object
      *
      * @param out 
      *
      * @throws IOException 
      */
     private void writeObject(java.io.ObjectOutputStream out)
       throws IOException {
       out.writeObject(inequalitySymbol);
       out.writeLong(timeStamp);
     }
  }
  
  
  
  1.12      +4 -3      logging-log4j/src/java/org/apache/log4j/chainsaw/help/tutorial.html
  
  Index: tutorial.html
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/help/tutorial.html,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- tutorial.html	12 May 2004 06:37:31 -0000	1.11
  +++ tutorial.html	20 Jun 2004 07:28:53 -0000	1.12
  @@ -176,9 +176,8 @@
   
   <p><b>Operator limitations:</b></p>
   <ul>
  -<li>The equality operator can be used with the LEVEL identifier, but for the comparison to succeed, the right hand value must be in all uppercase (this applies to the combination of LEVEL keyword and the equality operator only - for example, use <b>LEVEL == WARN</b> instead of <b>LEVEL == warn</b></li>
  -<li>Inequality operators are supported for Levels (<b>LEVEL &gt info</b>) and anything that can be converted to a numeric value.</li>
  -<li>Expressions using the timestamp field are not yet supported</li>
  +<li>Inequality operators are supported for Levels (<b>LEVEL &gt info</b>) and anything that can be converted to a numeric value (including timestamps).</li>
  +<li>In order to build expressions using the Timestamp field, provide the Timestamp value in this format: 'yyyy/MM/dd HH:mm:ss'.  Note the single ticks, which are required because of the space between the days and hours. The Timestamp field contains millisecond information, but the milliseconds are rounded off during event evaluation.</li>
   </ul>
   
   <p><B>Example expressions:</B></p>
  @@ -188,6 +187,8 @@
   <tr><td>To display all events which contain an exception</td><td><b>EXCEPTION EXISTS</b></td></tr>
   <tr><td>To display all events associated with a PROP key of USERID with a value of 'tester'</td><td><b>PROP.USERID == tester</b></td></tr>
   <tr><td>'and' the first and second examples together, 'or'd with the third</td><td><b>( LEVEL &gt= INFO && MSG ~= 'logged in' ) || EXCEPTION EXISTS</b></td></tr>
  +<tr><td>To display all events between 23:55 and 23:56 on the 19th of June</td><td><b>TIMESTAMP >= '2004/06/19 23:55:00' && TIMESTAMP <= '2004/06/19 23:56:00'</b></td></tr>
  +<tr><td>To display events occurring at 23:55:12 on the 19th of June (all events generated during that second, regardless of millisecond value)</td><td><b>TIMESTAMP == '2004/06/19 23:55:12'</b></td></tr>
   </table>
   
   <A NAME="color_filter"><h3>Color filters</h3>
  
  
  
  1.23      +6 -0      logging-log4j/src/java/org/apache/log4j/chainsaw/help/release-notes.html
  
  Index: release-notes.html
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/chainsaw/help/release-notes.html,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- release-notes.html	17 Jun 2004 00:18:05 -0000	1.22
  +++ release-notes.html	20 Jun 2004 07:28:53 -0000	1.23
  @@ -9,6 +9,12 @@
   
   <h1>1.99.99</h2>
   
  +<h2>19 June 2004</h2>
  +<ul>
  + <li>Expression rule enhancement:  Added support for evaluating the Timestamp field using the pattern 'yyyy/MM/dd HH:mm:ss' (ticks required).  Milliseconds are ignored (rounded down) during the evaluation of events.  This is true for inequality and equality evaluations.</li>
  + <li>Expression rule enhancement:  Level equality evaluations are now case-insensitive.</li>
  +</ul>
  +
   <h2>17 June 2004</h2>
   <ul>
    <li>Added application preference to authorize Chainsaw to have a null SecurityManager, which is required under Java Web Start
  
  
  

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