remm        01/08/06 12:21:55

  Modified:    catalina/src/share/org/apache/catalina/valves
                        AccessLogValve.java Constants.java
  Log:
  - Add a new combined mode for logging (logs the referer as well as the user-agent).
  - New alias name for the patterm (combined).
  - Patch submitted by Michael Smith <msmith at speedlegal.com>.
  
  Revision  Changes    Path
  1.9       +40 -2     
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java
  
  Index: AccessLogValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AccessLogValve.java       2001/07/24 23:21:09     1.8
  +++ AccessLogValve.java       2001/08/06 19:21:55     1.9
  @@ -119,6 +119,8 @@
    * commonly utilized patterns:</p>
    * <ul>
    * <li><b>common</b> - <code>%h %l %u %t "%r" %s %b</code>
  + * <li><b>combined</b> - 
  + *   <code>%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"</code>
    * </ul>
    *
    * <p><b>FIXME</b> - Improve the parsing so that things like
  @@ -126,7 +128,7 @@
    *
    * @author Craig R. McClanahan
    * @author Jason Brittain
  - * @version $Revision: 1.8 $ $Date: 2001/07/24 23:21:09 $
  + * @version $Revision: 1.9 $ $Date: 2001/08/06 19:21:55 $
    */
   
   public final class AccessLogValve
  @@ -195,6 +197,13 @@
   
   
       /**
  +     * For the combined format (common, plus useragent and referer), we do
  +     * the same
  +     */
  +    private boolean combined = false;
  +
  +
  +    /**
        * The pattern used to format our access log lines.
        */
       private String pattern = null;
  @@ -347,6 +356,8 @@
               pattern = "";
           if (pattern.equals(Constants.AccessLog.COMMON_ALIAS))
               pattern = Constants.AccessLog.COMMON_PATTERN;
  +        if (pattern.equals(Constants.AccessLog.COMBINED_ALIAS))
  +            pattern = Constants.AccessLog.COMBINED_PATTERN;
           this.pattern = pattern;
   
           if (this.pattern.equals(Constants.AccessLog.COMMON_PATTERN))
  @@ -354,6 +365,11 @@
           else
               common = false;
   
  +        if (this.pattern.equals(Constants.AccessLog.COMBINED_PATTERN))
  +            combined = true;
  +        else
  +            combined = false;
  +
       }
   
   
  @@ -449,7 +465,7 @@
           StringBuffer result = new StringBuffer();
   
           // Check to see if we should log using the "common" access log pattern
  -        if (common) {
  +        if (common || combined) {
               String value = null;
   
               ServletRequest req = request.getRequest();
  @@ -501,11 +517,33 @@
               result.append(space);
   
               int length = response.getContentCount();
  +
               if (length <= 0)
                   value = "-";
               else
                   value = "" + length;
               result.append(value);
  +
  +            if (combined) {
  +                result.append(space);
  +                result.append("\"");
  +                String referer = hreq.getHeader("referer");
  +                if(referer != null)
  +                    result.append(referer);
  +                else
  +                    result.append("-");
  +                result.append("\"");
  +
  +                result.append(space);
  +                result.append("\"");
  +                String ua = hreq.getHeader("user-agent");
  +                if(ua != null)
  +                    result.append(ua);
  +                else
  +                    result.append("-");
  +                result.append("\"");
  +            }
  +
           } else {
               // Generate a message based on the defined pattern
               boolean replace = false;
  
  
  
  1.3       +2 -0      
jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/valves/Constants.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Constants.java    2001/07/22 20:25:15     1.2
  +++ Constants.java    2001/08/06 19:21:55     1.3
  @@ -76,6 +76,8 @@
       public static final class AccessLog {
           public static final String COMMON_ALIAS = "common";
           public static final String COMMON_PATTERN = "%h %l %u %t \"%r\" %s %b";
  +        public static final String COMBINED_ALIAS = "combined";
  +        public static final String COMBINED_PATTERN = "%h %l %u %t \"%r\" %s %b 
\"%{Referer}i\" \"%{User-Agent}i\"";
       }
   
   }
  
  
  

Reply via email to