[logback-dev] svn commit: r846 - in logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic: . joran/action turbo

noreply.seb at qos.ch noreply.seb at qos.ch
Wed Nov 1 17:21:38 CET 2006


Author: seb
Date: Wed Nov  1 17:21:38 2006
New Revision: 846

Added:
   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/ClassicGlobal.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java
   logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/TurboFilter.java

Log:
ConfigurationAction now pushes and pops the context to and from the objectStack, so that it is usable
by following actions.
Added an implementation of TurboFilter that allows debug level for selected users only.
Work in progress: the <user> element still makes Joran caugh a bit.

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ClassicGlobal.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ClassicGlobal.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/ClassicGlobal.java	Wed Nov  1 17:21:38 2006
@@ -13,4 +13,5 @@
   static public final char LOGGER_SEPARATOR = '.';
   static public final String CAUSED_BY = "Caused by: ";
   static public final char DOT = '.';
+  static public final String USER_MDC_KEY = "user";
 }

Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java	(original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/joran/action/ConfigurationAction.java	Wed Nov  1 17:21:38 2006
@@ -34,6 +34,9 @@
  
       attachment = true;
     }
+    
+    // the context is turbo filter attachable, so it is pushed on top of the stack
+    ec.pushObject(getContext());
   }
 
   public void end(InterpretationContext ec, String name) {
@@ -42,5 +45,6 @@
       //LoggerContext loggerContext = (LoggerContext) context;
       //ConfiguratorBase.detachTemporaryConsoleAppender(repository, errorList);
     }
+    ec.popObject();
   }
 }

Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/turbo/DebugUsersTurboFilter.java	Wed Nov  1 17:21:38 2006
@@ -0,0 +1,46 @@
+package ch.qos.logback.classic.turbo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.filter.Filter;
+
+/**
+ * This class allows output of debug level events to a certain list of users.
+ * 
+ * If the level passed as a parameter is of level DEBUG, then the "user" value
+ * taken from the MDC is checked against the configured user list. When the user
+ * belongs to the list, the request is accepted. Otherwise a NEUTRAL response
+ * is sent, thus not influencing the filter chain.  
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ * @author S&eacute;bastien Pennec
+ */
+public class DebugUsersTurboFilter extends TurboFilter {
+
+  List<String> userList = new ArrayList<String>(); 
+  
+  @Override
+  public int decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+    if (!level.equals(Level.DEBUG)) {
+      return Filter.NEUTRAL;
+    } 
+    String user = MDC.get(ClassicGlobal.USER_MDC_KEY);
+    if (user != null && userList.contains(user)) {
+      return Filter.ACCEPT;
+    }
+    return Filter.NEUTRAL;
+  }
+  
+  public void addUser(String user) {
+    System.out.println("******* ADD USER CALLED");
+    userList.add(user);
+  }
+
+}

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  1 17:21:38 2006
@@ -23,7 +23,7 @@
   /**
    * Points to the next filter in the filter chain.
    */
-  private TurboFilter classicNext;
+  private TurboFilter turboNext;
 
   /**
    * Make a decision based on the multiple parameters passed as arguments.
@@ -58,14 +58,14 @@
    * Set the next filter pointer.
    */
   public void setNext(TurboFilter next) {
-    this.classicNext = next;
+    this.turboNext = next;
   }
 
   /**
    * Return the pointer to the next filter;
    */
   public TurboFilter getNext() {
-    return classicNext;
+    return turboNext;
   }
   
   public String getName() {



More information about the logback-dev mailing list