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/04/03 09:35:53 UTC

cvs commit: logging-log4j/src/java/org/apache/log4j/rule LevelInequalityRule.java LikeRule.java

sdeboy      2004/04/02 23:35:53

  Modified:    src/java/org/apache/log4j/rule LevelInequalityRule.java
                        LikeRule.java
  Log:
  LikeRule and LevelInequalityRule serialization now supported - previously failed due to non-serializable Level and ORO references
  
  Revision  Changes    Path
  1.5       +47 -8     logging-log4j/src/java/org/apache/log4j/rule/LevelInequalityRule.java
  
  Index: LevelInequalityRule.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/LevelInequalityRule.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- LevelInequalityRule.java	27 Feb 2004 16:47:34 -0000	1.4
  +++ LevelInequalityRule.java	3 Apr 2004 07:35:53 -0000	1.5
  @@ -16,26 +16,29 @@
   
   package org.apache.log4j.rule;
   
  +import java.io.IOException;
  +import java.util.Iterator;
  +import java.util.LinkedList;
  +import java.util.List;
  +
   import org.apache.log4j.Level;
   import org.apache.log4j.UtilLoggingLevel;
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.LoggingEventFieldResolver;
   
  -import java.util.Iterator;
  -import java.util.LinkedList;
  -import java.util.List;
  -
   /**
    * A Rule class implementing inequality evaluation for Levels (log4j and util.logging) using the toInt method.
    * 
    * @author Scott Deboy <sd...@apache.org>
    */
   public class LevelInequalityRule extends AbstractRule {
  +  static final long serialVersionUID = 851854546425717836L;
  +
     private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
  -  private final Level level;
  -  private final List utilList = new LinkedList();
  -  private final List levelList = new LinkedList();
  -  private final String inequalitySymbol;
  +  private transient Level level;
  +  private transient List utilList = new LinkedList();
  +  private transient List levelList = new LinkedList();
  +  private transient String inequalitySymbol;
   
     private LevelInequalityRule(
       String inequalitySymbol, String value) {
  @@ -89,4 +92,40 @@
   
       return result;
     }
  +  
  +  /**
  +    * Deserialize the state of the object
  +    *
  +    * @param in 
  +    *
  +    * @throws IOException 
  +    * @throws ClassNotFoundException 
  +    */
  +   private void readObject(java.io.ObjectInputStream in)
  +     throws IOException, ClassNotFoundException {
  +     utilList = new LinkedList();
  +     levelList = new LinkedList();
  +     inequalitySymbol = (String)in.readObject();
  +     boolean isUtilLogging = in.readBoolean();
  +     int levelInt = in.readInt();
  +     if (isUtilLogging) {
  +         level = UtilLoggingLevel.toLevel(levelInt);
  +     } else {
  +         level = Level.toLevel(levelInt);
  +     }
  +   }
  +
  +   /**
  +    * Serialize the state of the object
  +    *
  +    * @param out 
  +    *
  +    * @throws IOException 
  +    */
  +   private void writeObject(java.io.ObjectOutputStream out)
  +     throws IOException {
  +     out.writeObject(inequalitySymbol);
  +     out.writeBoolean(level instanceof UtilLoggingLevel);
  +     out.writeInt(level.toInt());
  +   }
   }
  
  
  
  1.6       +42 -6     logging-log4j/src/java/org/apache/log4j/rule/LikeRule.java
  
  Index: LikeRule.java
  ===================================================================
  RCS file: /home/cvs/logging-log4j/src/java/org/apache/log4j/rule/LikeRule.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- LikeRule.java	25 Mar 2004 03:39:24 -0000	1.5
  +++ LikeRule.java	3 Apr 2004 07:35:53 -0000	1.6
  @@ -16,26 +16,28 @@
   
   package org.apache.log4j.rule;
   
  +import java.io.IOException;
  +import java.util.Stack;
  +
   import org.apache.log4j.spi.LoggingEvent;
   import org.apache.log4j.spi.LoggingEventFieldResolver;
  -
   import org.apache.oro.text.regex.MalformedPatternException;
   import org.apache.oro.text.regex.Pattern;
   import org.apache.oro.text.regex.Perl5Compiler;
   import org.apache.oro.text.regex.Perl5Matcher;
   
  -import java.util.Stack;
  -
   /**
    * A Rule class providing support for ORO-based regular expression syntax. 
    * 
    * @author Scott Deboy <sd...@apache.org>
    */
   public class LikeRule extends AbstractRule {
  +  static final long serialVersionUID = -3375458885595683156L;
  +
     private static final LoggingEventFieldResolver resolver = LoggingEventFieldResolver.getInstance();
  -  private final Pattern pattern;
  -  private final Perl5Matcher matcher = new Perl5Matcher();
  -  private final String field;
  +  private transient Pattern pattern;
  +  private transient Perl5Matcher matcher = new Perl5Matcher();
  +  private transient String field;
   
     private LikeRule(String field, Pattern pattern) {
       if (!resolver.isField(field)) {
  @@ -73,4 +75,38 @@
       Object input = resolver.getValue(field, event);
       return ((input != null) && (pattern != null) && (matcher.matches(input.toString(), pattern)));
     }
  +  
  +  /**
  +    * Deserialize the state of the object
  +    *
  +    * @param in 
  +    *
  +    * @throws IOException 
  +    * @throws ClassNotFoundException 
  +    */
  +   private void readObject(java.io.ObjectInputStream in)
  +     throws IOException, ClassNotFoundException {
  +         try {
  +           field = (String)in.readObject();
  +           String patternString = (String)in.readObject();
  +           Perl5Compiler compiler = new Perl5Compiler();
  +           matcher = new Perl5Matcher();
  +           pattern = compiler.compile(patternString, Perl5Compiler.CASE_INSENSITIVE_MASK);
  +         } catch (MalformedPatternException e) {
  +             throw new IOException("Invalid LIKE rule - " + e.getMessage());
  +         }
  +   }
  +
  +   /**
  +    * Serialize the state of the object
  +    *
  +    * @param out 
  +    *
  +    * @throws IOException 
  +    */
  +   private void writeObject(java.io.ObjectOutputStream out)
  +     throws IOException {
  +     out.writeObject(field);
  +     out.writeObject(pattern.getPattern());
  +   }
   }
  
  
  

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