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

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Nov 29 19:30:29 CET 2006


Author: seb
Date: Wed Nov 29 19:30:29 2006
New Revision: 1035

Added:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java
Removed:
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/UserTurboFilter.java

Log:
Modified UserTurboFilter
Now using MDCTurboFilter

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/MDCTurboFilter.java	Wed Nov 29 19:30:29 2006
@@ -0,0 +1,56 @@
+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.classic.MDC;
+import ch.qos.logback.core.spi.FilterReply;
+
+/**
+ * This class allows output for a given MDC value.
+ * 
+ * When the given value is identified by this TubroFilter, 
+ * the reply is based on the OnMatch option.
+ * The information is taken from the MDC. For this TurboFilter to work,
+ * one must set the key that will be used to 
+ * access the information in the MDC.
+ * 
+ * To allow output for the value, set the OnMatch option
+ * to ACCEPT. To disable output for the given value, set
+ * the OnMatch option to DENY.
+ * 
+ * By default, values of the OnMatch and OnMisMatch
+ * options are NEUTRAL.
+ * 
+ *
+ * @author Ceki Gülcü
+ * @author Sébastien Pennec
+ */
+public class MDCTurboFilter extends TurboFilter {
+
+  String MDCKey;
+  String value;
+  
+  @Override
+  public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+    if (MDCKey == null) {
+      return FilterReply.NEUTRAL;
+    }
+    
+    String value = MDC.get(MDCKey);
+    if (this.value.equals(value)) {
+      return onMatch;
+    }
+    return onMismatch;
+  }
+  
+  public void setValue(String value) {
+    this.value = value;
+  }
+  
+  public void setMDCKey(String MDCKey) {
+    this.MDCKey = MDCKey;
+  }
+
+}



More information about the logback-dev mailing list