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

noreply.seb at qos.ch noreply.seb at qos.ch
Mon Jan 8 11:06:46 CET 2007


Author: seb
Date: Mon Jan  8 11:06:45 2007
New Revision: 1168

Added:
   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/ThresholdFilter.java

Log:
Added ThresholdFilter class and modified LevelFilter class. The latter now acts as a configurable
filter to allow or deny a specific given level. ThresholdFilter allows any logging events whose level is
higher or equals to its configured level.

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/LevelFilter.java	Mon Jan  8 11:06:45 2007
@@ -0,0 +1,45 @@
+package ch.qos.logback.classic.filter;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.spi.LoggingEvent;
+import ch.qos.logback.core.filter.AbstractMatcherFilter;
+import ch.qos.logback.core.spi.FilterReply;
+
+/**
+ * A class that filters events depending on their level.
+ * 
+ * One can specify a level and the behaviour of the filter when 
+ * said level is encountered in a logging event.
+ *
+ * @author Ceki Gülcü
+ * @author Sébastien Pennec
+ */
+public class LevelFilter extends AbstractMatcherFilter {
+
+  Level level;
+  
+  @Override
+  public FilterReply decide(Object eventObject) {
+    if (!isStarted()) {
+      return FilterReply.NEUTRAL;
+    }
+    
+    LoggingEvent event = (LoggingEvent)eventObject;
+    
+    if (event.getLevel().equals(level)) {
+      return onMatch;
+    } else {
+      return onMismatch;
+    }
+  }
+  
+  public void setLevel(String level) {
+    this.level = Level.toLevel(level);
+  }
+  
+  public void start() {
+    if (this.level != null) {
+      super.start();
+    }
+  }
+}

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/ThresholdFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/filter/ThresholdFilter.java	Mon Jan  8 11:06:45 2007
@@ -0,0 +1,45 @@
+package ch.qos.logback.classic.filter;
+
+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.spi.FilterReply;
+
+/**
+ * A class that filters events depending on their level.
+ * 
+ * All events with a level equal or above the specified
+ * level will be accepted, while all events with a level
+ * under the specified level will be denied.
+ *
+ * @author Sébastien Pennec
+ */
+public class ThresholdFilter extends Filter {
+
+  Level level;
+  
+  @Override
+  public FilterReply decide(Object eventObject) {
+    if (!isStarted()) {
+      return FilterReply.NEUTRAL;
+    }
+    
+    LoggingEvent event = (LoggingEvent)eventObject;
+    
+    if (event.getLevel().isGreaterOrEqual(level)) {
+      return FilterReply.ACCEPT;
+    } else {
+      return FilterReply.DENY;
+    }
+  }
+  
+  public void setLevel(String level) {
+    this.level = Level.toLevel(level);
+  }
+  
+  public void start() {
+    if (this.level != null) {
+      super.start();
+    }
+  }
+}



More information about the logback-dev mailing list