[logback-dev] svn commit: r1147 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/filter logback-core/src/main/java/ch/qos/logback/core/filter

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Dec 22 11:10:00 CET 2006


Author: seb
Date: Fri Dec 22 11:10:00 2006
New Revision: 1147

Added:
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java
   logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java

Log:
Refactored filters.
There is now an intermediate class under Filter to provide onMatch and onMismatch options.

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java	Fri Dec 22 11:10:00 2006
@@ -2,10 +2,10 @@
 
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.spi.LoggingEvent;
-import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.filter.AbstractMatcherFilter;
 import ch.qos.logback.core.spi.FilterReply;
 
-public class LevelFilter extends Filter {
+public class LevelFilter extends AbstractMatcherFilter {
 
   Level level;
   
@@ -18,9 +18,9 @@
     LoggingEvent event = (LoggingEvent)eventObject;
     
     if (event.getLevel().isGreaterOrEqual(level)) {
-      return FilterReply.ACCEPT;
+      return onMatch;
     } else {
-      return FilterReply.DENY;
+      return onMismatch;
     }
   }
   

Added: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/AbstractMatcherFilter.java	Fri Dec 22 11:10:00 2006
@@ -0,0 +1,29 @@
+package ch.qos.logback.core.filter;
+
+import ch.qos.logback.core.spi.FilterReply;
+
+public abstract class AbstractMatcherFilter extends Filter {
+
+  protected FilterReply onMatch = FilterReply.NEUTRAL;
+  protected FilterReply onMismatch = FilterReply.NEUTRAL;
+
+  final public void setOnMatch(String action) {
+    if ("NEUTRAL".equals(action)) {
+      onMatch = FilterReply.NEUTRAL;
+    } else if ("ACCEPT".equals(action)) {
+      onMatch = FilterReply.ACCEPT;
+    } else if ("DENY".equals(action)) {
+      onMatch = FilterReply.DENY;
+    }
+  }
+
+  final public void setOnMismatch(String action) {
+    if ("NEUTRAL".equals(action)) {
+      onMismatch = FilterReply.NEUTRAL;
+    } else if ("ACCEPT".equals(action)) {
+      onMismatch = FilterReply.ACCEPT;
+    } else if ("DENY".equals(action)) {
+      onMismatch = FilterReply.DENY;
+    }
+  }  
+}

Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java	(original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/filter/EvaluatorFilter.java	Fri Dec 22 11:10:00 2006
@@ -22,33 +22,10 @@
  * @author Sébastien Pennec
  */
 
-public class EvaluatorFilter extends Filter {
+public class EvaluatorFilter extends AbstractMatcherFilter {
 
   EventEvaluator evaluator;
-  
-  protected FilterReply onMatch = FilterReply.NEUTRAL;
-  protected FilterReply onMismatch = FilterReply.NEUTRAL;
-
-  final public void setOnMatch(String action) {
-    if ("NEUTRAL".equals(action)) {
-      onMatch = FilterReply.NEUTRAL;
-    } else if ("ACCEPT".equals(action)) {
-      onMatch = FilterReply.ACCEPT;
-    } else if ("DENY".equals(action)) {
-      onMatch = FilterReply.DENY;
-    }
-  }
-
-  final public void setOnMismatch(String action) {
-    if ("NEUTRAL".equals(action)) {
-      onMismatch = FilterReply.NEUTRAL;
-    } else if ("ACCEPT".equals(action)) {
-      onMismatch = FilterReply.ACCEPT;
-    } else if ("DENY".equals(action)) {
-      onMismatch = FilterReply.DENY;
-    }
-  }
-  
+    
   @Override
   public void start() {
     if(evaluator != null) {



More information about the logback-dev mailing list