[logback-dev] svn commit: r1036 - in logback/trunk/logback-classic: . lib src/main/java/ch/qos/logback/classic/turbo src/test/java/ch/qos/logback/classic src/test/java/ch/qos/logback/classic/turbo

noreply.ceki at qos.ch noreply.ceki at qos.ch
Wed Nov 29 20:51:05 CET 2006


Author: ceki
Date: Wed Nov 29 20:51:05 2006
New Revision: 1036

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MarkerTurboFilter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MatchingTurboFilter.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
      - copied unchanged from r1035, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/MarkerTurboFilterTest.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/PackageTest.java
Removed:
   logback/trunk/logback-classic/build.properties
   logback/trunk/logback-classic/build.xml
   logback/trunk/logback-classic/lib/
   logback/trunk/logback-classic/mdcfilter.xml
   logback/trunk/logback-classic/site.xml
   logback/trunk/logback-classic/slf4j.xml
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java
   logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java

Log:
- removed a bunch of unused jars and other files.
- Added MatchingTurboFilter which takes over some responsability from TurboFilter
- Added corresponding test cases

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java	Wed Nov 29 20:51:05 2006
@@ -27,7 +27,7 @@
  * @author Ceki Gülcü
  * @author Sébastien Pennec
  */
-public class MDCTurboFilter extends TurboFilter {
+public class MDCTurboFilter extends MatchingTurboFilter {
 
   String MDCKey;
   String value;

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MarkerTurboFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MarkerTurboFilter.java	Wed Nov 29 20:51:05 2006
@@ -0,0 +1,50 @@
+package ch.qos.logback.classic.turbo;
+
+import org.slf4j.Marker;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.core.spi.FilterReply;
+
+/**
+ * Checks whether the marker in the event matches the marker specified by the user as a property.
+ */
+public class MarkerTurboFilter extends MatchingTurboFilter {
+
+  Marker marker2Match;
+
+  @Override
+  public void start() {
+    if(marker2Match != null) {
+      super.start();
+    } else {
+      addError("The marker property must be set for ["+getName()+"]");
+    }
+  }
+  
+  @Override
+  public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+    if(!isStarted()) {
+      return FilterReply.NEUTRAL;
+    }
+    
+    if(marker == null) {
+      return onMismatch;
+    } 
+    
+    if(marker2Match.contains(marker)) {
+      return onMatch;
+    } else {
+      return onMismatch;
+    }
+  }
+
+  /**
+   * The marker to match in the event.
+   * 
+   * @param marker2Match
+   */
+  public void setMarker(Marker marker2Match) {
+    this.marker2Match = marker2Match;
+  }
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MatchingTurboFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MatchingTurboFilter.java	Wed Nov 29 20:51:05 2006
@@ -0,0 +1,35 @@
+package ch.qos.logback.classic.turbo;
+
+import ch.qos.logback.core.spi.FilterReply;
+
+/**
+ * An abstract class containing support for {@link #onMatch} on {@link #onMismatch} 
+ * attributes, shared by many but not all tubo filters.
+ *  
+ * @author Ceki Gulcu
+ */
+public abstract class MatchingTurboFilter extends TurboFilter {
+
+  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-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java	Wed Nov 29 20:51:05 2006
@@ -9,9 +9,9 @@
 import ch.qos.logback.core.spi.LifeCycle;
 
 /**
- * TurboFilter is a specialized filter with a decide method that takes a bunch of parameters
- * instead of a single event object. The latter is cleaner but the latter is much more 
- * performant.
+ * TurboFilter is a specialized filter with a decide method that takes a bunch 
+ * of parameters instead of a single event object. The latter is cleaner but 
+ * the latter is much more performant.
  * 
  * @author Ceki Gulcu
  */
@@ -19,9 +19,7 @@
 
   private String name;
   boolean start = false;  
-  protected FilterReply onMatch = FilterReply.NEUTRAL;
-  protected FilterReply onMismatch = FilterReply.NEUTRAL;
-
+ 
   
   /**
    * Points to the next filter in the filter chain.
@@ -51,12 +49,10 @@
   public boolean isStarted() {
     return this.start;
   }
-
+ 
   public void stop() {
     this.start = false;
   }
-  
-  
   /**
    * Set the next filter pointer.
    */
@@ -78,25 +74,4 @@
   public void setName(String name) {
     this.name = name;
   }
-  
-  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-classic/src/test/java/ch/qos/logback/classic/AllTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java	(original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/AllTest.java	Wed Nov 29 20:51:05 2006
@@ -28,6 +28,7 @@
     suite.addTest(ch.qos.logback.classic.pattern.PackageTest.suite()); 
     suite.addTest(ch.qos.logback.classic.db.PackageTest.suite()); 
     suite.addTest(ch.qos.logback.classic.spi.PackageTest.suite()); 
+    suite.addTest(ch.qos.logback.classic.turbo.PackageTest.suite()); 
     return suite;
   }
 }

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/MarkerTurboFilterTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/MarkerTurboFilterTest.java	Wed Nov 29 20:51:05 2006
@@ -0,0 +1,49 @@
+package ch.qos.logback.classic.turbo;
+
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+
+import ch.qos.logback.core.spi.FilterReply;
+
+import junit.framework.TestCase;
+
+public class MarkerTurboFilterTest extends TestCase {
+
+  static String MARKER_NAME = "toto";
+  
+  Marker totoMarker = MarkerFactory.getMarker(MARKER_NAME);
+  
+  public MarkerTurboFilterTest(String arg0) {
+    super(arg0);
+  }
+
+  protected void setUp() throws Exception {
+    super.setUp();
+  }
+
+  protected void tearDown() throws Exception {
+    super.tearDown();
+  }
+
+  public void testNoMarker() {
+    MarkerTurboFilter mkt = new MarkerTurboFilter();
+    mkt.start();
+    assertFalse(mkt.isStarted());
+    assertEquals(FilterReply.NEUTRAL, mkt.decide(totoMarker, null, null, null, null, null));
+    assertEquals(FilterReply.NEUTRAL, mkt.decide(null, null, null, null, null, null));
+
+  }
+  
+  public void testBasic() {
+    MarkerTurboFilter mkt = new MarkerTurboFilter();
+    mkt.setMarker(totoMarker);
+    mkt.setOnMatch("ACCEPT");
+    mkt.setOnMismatch("DENY");
+
+    mkt.start();
+    assertTrue(mkt.isStarted());
+    assertEquals(FilterReply.DENY, mkt.decide(null, null, null, null, null, null));
+    assertEquals(FilterReply.ACCEPT, mkt.decide(totoMarker, null, null, null, null, null));
+  }
+  
+}

Added: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/PackageTest.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/turbo/PackageTest.java	Wed Nov 29 20:51:05 2006
@@ -0,0 +1,24 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ * 
+ * Copyright (C) 1999-2006, QOS.ch
+ * 
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
+ */
+package ch.qos.logback.classic.turbo;
+
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+public class PackageTest extends TestCase {
+  
+  public static Test suite() {
+    TestSuite suite = new TestSuite();
+    suite.addTestSuite(MarkerTurboFilterTest.class);
+    return suite;
+  }
+}
\ No newline at end of file



More information about the logback-dev mailing list