[logback-dev] svn commit: r612 - in logback/trunk/logback-access/src/main/java/ch/qos/logback/access: . pattern spi tomcat

noreply.seb at qos.ch noreply.seb at qos.ch
Fri Sep 29 12:11:12 CEST 2006


Author: seb
Date: Fri Sep 29 12:11:12 2006
New Revision: 612

Added:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java
Modified:
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
   logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/TomcatServerAdapter.java

Log:
- added a RequestParameterConverter, that works just like the RequestAttributeConverter except for one small obvious detail
- added several patterns to PatternLayout

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/PatternLayout.java	Fri Sep 29 12:11:12 2006
@@ -16,16 +16,21 @@
 import ch.qos.logback.access.pattern.DateConverter;
 import ch.qos.logback.access.pattern.LineSeparatorConverter;
 import ch.qos.logback.access.pattern.LocalIPAddressConverter;
+import ch.qos.logback.access.pattern.LocalPortConverter;
 import ch.qos.logback.access.pattern.NAConverter;
 import ch.qos.logback.access.pattern.PostContentConverter;
 import ch.qos.logback.access.pattern.RemoteHostConverter;
 import ch.qos.logback.access.pattern.RemoteIPAddressConverter;
 import ch.qos.logback.access.pattern.RemoteUserConverter;
+import ch.qos.logback.access.pattern.RequestAttributeConverter;
+import ch.qos.logback.access.pattern.RequestCookieConverter;
 import ch.qos.logback.access.pattern.RequestHeaderConverter;
 import ch.qos.logback.access.pattern.RequestMethodConverter;
+import ch.qos.logback.access.pattern.RequestParameterConverter;
 import ch.qos.logback.access.pattern.RequestProtocolConverter;
 import ch.qos.logback.access.pattern.RequestURIConverter;
 import ch.qos.logback.access.pattern.RequestURLConverter;
+import ch.qos.logback.access.pattern.ResponseHeaderConverter;
 import ch.qos.logback.access.pattern.ServerNameConverter;
 import ch.qos.logback.access.pattern.StatusCodeConverter;
 import ch.qos.logback.access.spi.AccessEvent;
@@ -71,7 +76,6 @@
     defaultConverterMap.put("s", StatusCodeConverter.class.getName());
     defaultConverterMap.put("statusCode", StatusCodeConverter.class.getName());
 
-
     defaultConverterMap.put("t", DateConverter.class.getName());
     defaultConverterMap.put("date", DateConverter.class.getName());
 
@@ -87,6 +91,11 @@
     defaultConverterMap.put("p", PostContentConverter.class.getName());
     defaultConverterMap.put("post", PostContentConverter.class.getName());
     
+    defaultConverterMap.put("localPort", LocalPortConverter.class.getName());
+    defaultConverterMap.put("reqAttribute", RequestAttributeConverter.class.getName());
+    defaultConverterMap.put("reqCookie", RequestCookieConverter.class.getName());
+    defaultConverterMap.put("responseHeader", ResponseHeaderConverter.class.getName());
+    defaultConverterMap.put("reqParameter", RequestParameterConverter.class.getName());
   }
   
   public PatternLayout() {

Added: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/pattern/RequestParameterConverter.java	Fri Sep 29 12:11:12 2006
@@ -0,0 +1,28 @@
+package ch.qos.logback.access.pattern;
+
+import ch.qos.logback.access.spi.AccessEvent;
+import ch.qos.logback.core.util.OptionHelper;
+
+
+public class RequestParameterConverter extends AccessConverter {
+
+  String key;
+
+  public void start() {
+    key = getFirstOption();
+    if (OptionHelper.isEmpty(key)) {
+      addWarn("Missing key for the request parameter");
+    } else {
+      super.start();
+    }
+  }
+
+  protected String convert(AccessEvent accessEvent) {
+    if (!isStarted()) {
+      return "INACTIVE_REQUEST_PARAM_CONV";
+    }
+
+    return accessEvent.getRequestParameter(key);
+  }
+
+}

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/spi/AccessEvent.java	Fri Sep 29 12:11:12 2006
@@ -1,5 +1,6 @@
 package ch.qos.logback.access.spi;
 
+import java.io.InputStream;
 import java.io.Serializable;
 import java.util.Enumeration;
 import java.util.HashMap;
@@ -229,6 +230,19 @@
     }
   }
 
+  public String getRequestParameter(String key) {
+    if (httpRequest != null) {
+      Object value = httpRequest.getParameter(key);
+      if (value == null) {
+        return AccessEvent.NA;
+      } else {
+        return value.toString();
+      }
+    } else {
+      return AccessEvent.NA;
+    }
+  }
+
   public String getCookie(String key) {
 
     if (httpRequest != null) {
@@ -249,7 +263,8 @@
   public long getContentLength() {
     if (contentLength == SENTINEL) {
       if (httpResponse != null) {
-        return serverAdapter.getContentLength();
+        contentLength = serverAdapter.getContentLength();
+        return contentLength;
         // if (httpResponse instanceof org.mortbay.jetty.Response) {
         // // TODO
         // } else if (httpResponse instanceof
@@ -271,7 +286,7 @@
   public int getStatusCode() {
     if (statusCode == SENTINEL) {
       if (httpResponse != null) {
-        return serverAdapter.getStatusCode();
+        statusCode = serverAdapter.getStatusCode();
         // if (httpResponse instanceof org.mortbay.jetty.Response) {
         // statusCode = ((org.mortbay.jetty.Response) httpResponse).getStatus();
         // } else if (httpResponse instanceof
@@ -295,7 +310,9 @@
     }
 
     try {
-      postContent = Util.readToString(httpRequest.getInputStream());
+      InputStream in = httpRequest.getInputStream();
+      System.out.println("********InputStream: " + in.toString());
+      postContent = Util.readToString(in);
     } catch (Exception ex) {
       // do nothing
     }

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/LogbackValve.java	Fri Sep 29 12:11:12 2006
@@ -147,7 +147,6 @@
   }
 
   public void backgroundProcess() {
-    // TODO Auto-generated method stub
   }
 
   public String getInfo() {

Modified: logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/TomcatServerAdapter.java
==============================================================================
--- logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/TomcatServerAdapter.java	(original)
+++ logback/trunk/logback-access/src/main/java/ch/qos/logback/access/tomcat/TomcatServerAdapter.java	Fri Sep 29 12:11:12 2006
@@ -21,7 +21,7 @@
   }
   
   public long getContentLength() {
-    return response.getContentCount();
+    return response.getContentLength();
   }
 
   public int getStatusCode() {



More information about the logback-dev mailing list