[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-30-gd786af4

added by portage for gitosis-gentoo git-noreply at pixie.qos.ch
Mon Nov 15 17:17:05 CET 2010


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".

The branch, master has been updated
       via  d786af4a6ee0b6f87d92678349ea5f7f7a9751de (commit)
      from  6fd071745b325bbf3cd8345a67b634895f6bb9bb (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=d786af4a6ee0b6f87d92678349ea5f7f7a9751de
http://github.com/ceki/logback/commit/d786af4a6ee0b6f87d92678349ea5f7f7a9751de

commit d786af4a6ee0b6f87d92678349ea5f7f7a9751de
Author: Ceki Gulcu <ceki at qos.ch>
Date:   Mon Nov 15 15:07:58 2010 +0100

    TeeFilter now takes include and exclude parameters so that it can be
    enabled or disabled by host.
    
    Added various defaults in ch/qos/logback/access/joran/JoranConfigurator

diff --git a/logback-access/src/main/java/ch/qos/logback/access/AccessConstants.java b/logback-access/src/main/java/ch/qos/logback/access/AccessConstants.java
index 107b928..9009aa8 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/AccessConstants.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/AccessConstants.java
@@ -25,4 +25,11 @@ public class AccessConstants {
   public final static String IMAGE_JPEG = "image/jpeg";
   public final static String IMAGE_GIF = "image/gif";
   public final static String IMAGE_PNG = "image/png";
+
+
+
+
+    public final static String TEE_FILTER_INCLUDES_PARAM = "includes";
+    public final static String TEE_FILTER_EXCLUDES_PARAM = "excludes";
+
 }
diff --git a/logback-access/src/main/java/ch/qos/logback/access/joran/JoranConfigurator.java b/logback-access/src/main/java/ch/qos/logback/access/joran/JoranConfigurator.java
index 3b1c45a..2b255ad 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/joran/JoranConfigurator.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/joran/JoranConfigurator.java
@@ -15,10 +15,14 @@ package ch.qos.logback.access.joran;
 
 
 import ch.qos.logback.access.PatternLayout;
+import ch.qos.logback.access.PatternLayoutEncoder;
+import ch.qos.logback.access.boolex.JaninoEventEvaluator;
 import ch.qos.logback.access.joran.action.ConfigurationAction;
 import ch.qos.logback.access.joran.action.EvaluatorAction;
 import ch.qos.logback.access.sift.SiftAction;
 import ch.qos.logback.core.AppenderBase;
+import ch.qos.logback.core.UnsynchronizedAppenderBase;
+import ch.qos.logback.core.filter.EvaluatorFilter;
 import ch.qos.logback.core.joran.JoranConfiguratorBase;
 import ch.qos.logback.core.joran.action.AppenderRefAction;
 import ch.qos.logback.core.joran.action.NOPAction;
@@ -51,6 +55,11 @@ public class JoranConfigurator extends JoranConfiguratorBase {
   protected void addDefaultNestedComponentRegistryRules(
       DefaultNestedComponentRegistry registry) {
     registry.add(AppenderBase.class, "layout", PatternLayout.class);
+          registry
+        .add(EvaluatorFilter.class, "evaluator", JaninoEventEvaluator.class);
+
+    registry.add(AppenderBase.class, "encoder", PatternLayoutEncoder.class);
+    registry.add(UnsynchronizedAppenderBase.class, "encoder", PatternLayoutEncoder.class);
   }
 
 }
diff --git a/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeFilter.java b/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeFilter.java
index 3469403..3d2b44b 100644
--- a/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeFilter.java
+++ b/logback-access/src/main/java/ch/qos/logback/access/servlet/TeeFilter.java
@@ -14,6 +14,10 @@
 package ch.qos.logback.access.servlet;
 
 import java.io.IOException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.servlet.Filter;
 import javax.servlet.FilterChain;
@@ -24,48 +28,112 @@ import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import ch.qos.logback.access.AccessConstants;
+import static ch.qos.logback.access.AccessConstants.LB_OUTPUT_BUFFER;
+import static ch.qos.logback.access.AccessConstants.TEE_FILTER_INCLUDES_PARAM;
+import static ch.qos.logback.access.AccessConstants.TEE_FILTER_EXCLUDES_PARAM;
+
 
 public class TeeFilter implements Filter {
 
-  public void destroy() {
-    // NOP
-  }
-
-  public void doFilter(ServletRequest request, ServletResponse response,
-      FilterChain filterChain) throws IOException, ServletException {
-
-    if (request instanceof HttpServletRequest) {
-      try {
-        TeeHttpServletRequest teeRequest = new TeeHttpServletRequest(
-            (HttpServletRequest) request);
-        TeeHttpServletResponse teeResponse = new TeeHttpServletResponse(
-            (HttpServletResponse) response);
-        
-        //System.out.println("BEFORE TeeFilter. filterChain.doFilter()");
-        filterChain.doFilter(teeRequest, teeResponse);
-        //System.out.println("AFTER TeeFilter. filterChain.doFilter()");
-
-        teeResponse.finish();
-        // let the output contents be available for later use by
-        // logback-access-logging
-        teeRequest.setAttribute(AccessConstants.LB_OUTPUT_BUFFER, teeResponse
-            .getOutputBuffer());
-      } catch (IOException e) {
-        e.printStackTrace();
-        throw e;
-      } catch (ServletException e) {
-        e.printStackTrace();
-        throw e;
-      }
-    } else {
-      filterChain.doFilter(request, response);
+    boolean active;
+
+    public void destroy() {
+        // NOP
     }
 
-  }
+    public void doFilter(ServletRequest request, ServletResponse response,
+                         FilterChain filterChain) throws IOException, ServletException {
+
+        if (active && request instanceof HttpServletRequest) {
+            try {
+                TeeHttpServletRequest teeRequest = new TeeHttpServletRequest(
+                        (HttpServletRequest) request);
+                TeeHttpServletResponse teeResponse = new TeeHttpServletResponse(
+                        (HttpServletResponse) response);
+
+                //System.out.println("BEFORE TeeFilter. filterChain.doFilter()");
+                filterChain.doFilter(teeRequest, teeResponse);
+                //System.out.println("AFTER TeeFilter. filterChain.doFilter()");
+
+                teeResponse.finish();
+                // let the output contents be available for later use by
+                // logback-access-logging
+                teeRequest.setAttribute(LB_OUTPUT_BUFFER, teeResponse
+                        .getOutputBuffer());
+            } catch (IOException e) {
+                e.printStackTrace();
+                throw e;
+            } catch (ServletException e) {
+                e.printStackTrace();
+                throw e;
+            }
+        } else {
+            filterChain.doFilter(request, response);
+        }
+
+    }
+
+    public void init(FilterConfig filterConfig) throws ServletException {
+        String includeListAsStr = filterConfig.getInitParameter(TEE_FILTER_INCLUDES_PARAM);
+        String excludeListAsStr = filterConfig.getInitParameter(TEE_FILTER_EXCLUDES_PARAM);
+        String localhostName = getLocalhostName();
+
+        active = computeActivation(localhostName, includeListAsStr, excludeListAsStr);
+        if (active)
+            System.out.println("TeeFilter will be ACTIVE on this host [" + localhostName + "]");
+        else
+            System.out.println("TeeFilter will be DISABLED on this host [" + localhostName + "]");
+
+    }
+
+    static List<String> extractNameList(String nameListAsStr) {
+        List<String> nameList = new ArrayList<String>();
+        if (nameListAsStr == null) {
+            return nameList;
+        }
+
+        nameListAsStr = nameListAsStr.trim();
+        if (nameListAsStr.length() == 0) {
+            return nameList;
+        }
 
-  public void init(FilterConfig arg0) throws ServletException {
-    // NOP
-  }
+        String[] nameArray = nameListAsStr.split("[,;]");
+        for (String n : nameArray) {
+            n = n.trim();
+            nameList.add(n);
+        }
+        return nameList;
+    }
+
+
+    static String getLocalhostName() {
+        String hostname = "127.0.0.1";
+
+        try {
+            hostname = InetAddress.getLocalHost().getHostName();
+        } catch (UnknownHostException uhe) {
+            uhe.printStackTrace();
+        }
+        return hostname;
+    }
+
+    static boolean computeActivation(String hostname, String includeListAsStr, String excludeListAsStr) {
+        List<String> includeList = extractNameList(includeListAsStr);
+        List<String> excludeList = extractNameList(excludeListAsStr);
+        boolean inIncludesList = mathesIncludesList(hostname, includeList);
+        boolean inExcludesList = mathesExcludesList(hostname, excludeList);
+        return inIncludesList && (!inExcludesList);
+    }
+
+
+    static boolean mathesIncludesList(String hostname, List<String> includeList) {
+        if (includeList.isEmpty()) return true;
+        return includeList.contains(hostname);
+    }
+
+    static boolean mathesExcludesList(String hostname, List<String> excludesList) {
+        if (excludesList.isEmpty()) return false;
+        return excludesList.contains(hostname);
+    }
 
 }
diff --git a/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java b/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java
index 255c095..ee455f3 100644
--- a/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java
+++ b/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java
@@ -23,6 +23,7 @@ import org.junit.runners.Suite.SuiteClasses;
     ch.qos.logback.access.pattern.PackageTest.class,
     ch.qos.logback.access.jetty.PackageTest.class,
     ch.qos.logback.access.filter.PackageTest.class,
+    ch.qos.logback.access.servlet.PackageTest.class,
     ch.qos.logback.access.sift.PackageTest.class })
 public class AllAccessTest {
 
diff --git a/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java b/logback-access/src/test/java/ch/qos/logback/access/servlet/PackageTest.java
similarity index 61%
copy from logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java
copy to logback-access/src/test/java/ch/qos/logback/access/servlet/PackageTest.java
index 255c095..22ce2cc 100644
--- a/logback-access/src/test/java/ch/qos/logback/access/AllAccessTest.java
+++ b/logback-access/src/test/java/ch/qos/logback/access/servlet/PackageTest.java
@@ -11,19 +11,15 @@
  * under the terms of the GNU Lesser General Public License version 2.1
  * as published by the Free Software Foundation.
  */
-package ch.qos.logback.access;
+package ch.qos.logback.access.servlet;
 
+import ch.qos.logback.access.filter.StatsByDayTest;
+import junit.framework.TestCase;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 import org.junit.runners.Suite.SuiteClasses;
 
 @RunWith(Suite.class)
- at SuiteClasses( { ch.qos.logback.access.spi.PackageTest.class,
-    ch.qos.logback.access.net.PackageTest.class,
-    ch.qos.logback.access.pattern.PackageTest.class,
-    ch.qos.logback.access.jetty.PackageTest.class,
-    ch.qos.logback.access.filter.PackageTest.class,
-    ch.qos.logback.access.sift.PackageTest.class })
-public class AllAccessTest {
-
-}
+ at SuiteClasses({TeeFilterTest.class})
+public class PackageTest extends TestCase {
+}
\ No newline at end of file
diff --git a/logback-access/src/test/java/ch/qos/logback/access/servlet/TeeFilterTest.java b/logback-access/src/test/java/ch/qos/logback/access/servlet/TeeFilterTest.java
new file mode 100644
index 0000000..f550de5
--- /dev/null
+++ b/logback-access/src/test/java/ch/qos/logback/access/servlet/TeeFilterTest.java
@@ -0,0 +1,57 @@
+package ch.qos.logback.access.servlet;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+public class TeeFilterTest {
+
+
+    @Test
+    public void extractNameList() {
+        assertEquals(Arrays.asList(new String[]{"a"}), TeeFilter.extractNameList("a"));
+        assertEquals(Arrays.asList(new String[]{"a", "b"}), TeeFilter.extractNameList("a, b"));
+        assertEquals(Arrays.asList(new String[]{"a", "b"}), TeeFilter.extractNameList("a; b"));
+        assertEquals(Arrays.asList(new String[]{"a", "b", "c"}), TeeFilter.extractNameList("a; b, c"));
+    }
+
+    @Test
+    public void defaultCase() {
+        assertTrue(TeeFilter.computeActivation("somehost", "", ""));
+        assertTrue(TeeFilter.computeActivation("somehost", null, null));
+    }
+
+    @Test
+    public void withIncludesOnly() {
+        assertTrue(TeeFilter.computeActivation("a", "a", null));
+        assertTrue(TeeFilter.computeActivation("a", "a, b", null));
+        assertFalse(TeeFilter.computeActivation("a", "b", null));
+        assertFalse(TeeFilter.computeActivation("a", "b, c", null));
+    }
+
+
+    @Test
+    public void withExcludesOnly() {
+        assertFalse(TeeFilter.computeActivation("a", null, "a"));
+        assertFalse(TeeFilter.computeActivation("a", null, "a, b"));
+        assertTrue(TeeFilter.computeActivation("a", null, "b"));
+        assertTrue(TeeFilter.computeActivation("a", null, "b, c"));
+    }
+
+
+    @Test
+    public void withIncludesAndExcludes() {
+        assertFalse(TeeFilter.computeActivation("a", "a", "a"));
+        assertTrue(TeeFilter.computeActivation("a", "a", "b"));
+        assertFalse(TeeFilter.computeActivation("a", "b", "a"));
+        assertFalse(TeeFilter.computeActivation("a", "b", "b"));
+
+    }
+
+}
diff --git a/logback-site/src/site/pages/news.html b/logback-site/src/site/pages/news.html
index 555f7d7..86a5035 100644
--- a/logback-site/src/site/pages/news.html
+++ b/logback-site/src/site/pages/news.html
@@ -44,6 +44,9 @@
     requested by Michael Osipov.
     </p>
 
+    <p><code>TeeFilter</code> now takes include and exclude parameters
+    so that it can be enabled or disabled by host.</p>
+
     <h3>20th of October, 2010 - Release of version 0.9.26</h3>
 
 

-----------------------------------------------------------------------

Summary of changes:
 .../ch/qos/logback/access/AccessConstants.java     |    7 +
 .../logback/access/joran/JoranConfigurator.java    |    9 ++
 .../ch/qos/logback/access/servlet/TeeFilter.java   |  142 +++++++++++++++-----
 .../java/ch/qos/logback/access/AllAccessTest.java  |    1 +
 .../access/{net => servlet}/PackageTest.java       |    6 +-
 .../qos/logback/access/servlet/TeeFilterTest.java  |   57 ++++++++
 logback-site/src/site/pages/news.html              |    3 +
 7 files changed, 185 insertions(+), 40 deletions(-)
 copy logback-access/src/test/java/ch/qos/logback/access/{net => servlet}/PackageTest.java (84%)
 create mode 100644 logback-access/src/test/java/ch/qos/logback/access/servlet/TeeFilterTest.java


hooks/post-receive
-- 
Logback: the generic, reliable, fast and flexible logging framework.


More information about the logback-dev mailing list