[logback-dev] svn commit: r925 - logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Nov 17 09:51:46 CET 2006


Author: seb
Date: Fri Nov 17 09:51:45 2006
New Revision: 925

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/UserTurboFilter.java
Modified:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java

Log:
Added support for OnMatch and OnMismatch options in TurboFilter
Added a new TurboFilter: UserTurboFilter

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	Fri Nov 17 09:51:45 2006
@@ -4,7 +4,6 @@
 
 import ch.qos.logback.classic.Level;
 import ch.qos.logback.classic.Logger;
-import ch.qos.logback.core.filter.Filter;
 import ch.qos.logback.core.spi.ContextAwareBase;
 import ch.qos.logback.core.spi.FilterReply;
 import ch.qos.logback.core.spi.LifeCycle;
@@ -19,7 +18,10 @@
 public abstract class TurboFilter extends ContextAwareBase implements LifeCycle {
 
   private String name;
-  boolean start = false;
+  boolean start = false;  
+  protected FilterReply onMatch = FilterReply.NEUTRAL;
+  protected FilterReply onMismatch = FilterReply.NEUTRAL;
+
   
   /**
    * Points to the next filter in the filter chain.
@@ -28,8 +30,8 @@
 
   /**
    * Make a decision based on the multiple parameters passed as arguments.
-   * The returned value should be one of <code>{@link Filter#DENY}</code>, 
-   * <code>{@link Filter#NEUTRAL}</code>, or <code>{@link Filter#ACCEPT}</code>.
+   * The returned value should be one of <code>{@link FilterReply#DENY}</code>, 
+   * <code>{@link FilterReply#NEUTRAL}</code>, or <code>{@link FilterReply#ACCEPT}</code>.
   
    * @param marker
    * @param logger
@@ -76,5 +78,25 @@
   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;
+    }
+  }
 
 }

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/UserTurboFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/UserTurboFilter.java	Fri Nov 17 09:51:45 2006
@@ -0,0 +1,45 @@
+package ch.qos.logback.classic.turbo;
+
+import org.slf4j.Marker;
+
+import ch.qos.logback.classic.ClassicGlobal;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.MDC;
+import ch.qos.logback.core.spi.FilterReply;
+
+/**
+ * This class allows output for a given user.
+ * 
+ * When the given user is identified by this TubroFilter, 
+ * the reply is based on the OnMatch option.
+ * 
+ * To allow output for a user, set the OnMatch option
+ * to ACCEPT. To disable output for the given user, set
+ * the OnMatch option to DENY.
+ * 
+ * By default, values of the OnMatch and OnMisMatch
+ * options are NEUTRAL.
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ * @author S&eacute;bastien Pennec
+ */
+public class UserTurboFilter extends TurboFilter {
+
+  String user;
+  
+  @Override
+  public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+
+    String user = MDC.get(ClassicGlobal.USER_MDC_KEY);
+    if (this.user.equals(user)) {
+      return onMatch;
+    }
+    return onMismatch;
+  }
+  
+  public void setUser(String user) {
+    this.user = user;
+  }
+
+}



More information about the logback-dev mailing list