funkman     2003/06/04 09:58:21

  Modified:    catalina/src/share/org/apache/catalina/valves
                        mbeans-descriptors.xml ExtendedAccessLogValve.java
                        AccessLogValve.java
  Log:
  Fix bz - 20380 AccessLogValve incorrectly calculates timezone
  Enc bz - 16374 Date in file name configurable
  Enc bz - 16400 Allow logging to be conditional
  
  Revision  Changes    Path
  1.3       +13 -1     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/mbeans-descriptors.xml
  
  Index: mbeans-descriptors.xml
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/mbeans-descriptors.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- mbeans-descriptors.xml    1 Jun 2003 20:57:00 -0000       1.2
  +++ mbeans-descriptors.xml    4 Jun 2003 16:58:21 -0000       1.3
  @@ -38,13 +38,21 @@
                  type="boolean"/>
   
       <attribute name="rotatable"
  -               description="Rotate log"
  +               description="Flag to indicate automatic log rotation."
                  is="true"
                  type="boolean"/>
   
       <attribute name="suffix"
                  description="The suffix that is added to log file filenames"
                  type="java.lang.String"/>
  +
  +    <attribute name="condition"
  +               description="The value to look for conditional logging."
  +               type="java.lang.String"/>
  +
  +    <attribute name="fileDateFormat"
  +               description="The format for the date date based log rotation."
  +               type="java.lang.String"/>
     </mbean>
   
     <mbean name="CertificatesValve"
  @@ -158,6 +166,10 @@
   
       <attribute name="suffix"
                  description="The suffix that is added to log file filenames"
  +               type="java.lang.String"/>
  +
  +    <attribute name="fileDateFormat"
  +               description="The format for the date date based log rotation."
                  type="java.lang.String"/>
   
       <operation name="rotate"
  
  
  
  1.3       +28 -5     
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ExtendedAccessLogValve.java
  
  Index: ExtendedAccessLogValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/ExtendedAccessLogValve.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ExtendedAccessLogValve.java       3 Jun 2003 23:37:05 -0000       1.2
  +++ ExtendedAccessLogValve.java       4 Jun 2003 16:58:21 -0000       1.3
  @@ -359,6 +359,10 @@
       private boolean checkExists = false;
   
   
  +    /**
  +     * Date format to place in log file name. Use at your own risk!
  +     */
  +    private String fileDateFormat = null;
   
   
       // ------------------------------------------------------------- Properties
  @@ -535,6 +539,23 @@
   
       }
   
  +
  +    /**
  +     *  Return the date format date based log rotation.
  +     */
  +    public String getFileDateFormat() {
  +        return fileDateFormat;
  +    }
  +
  +
  +    /**
  +     *  Set the date format date based log rotation.
  +     */
  +    public void setFileDateFormat(String fileDateFormat) {
  +        this.fileDateFormat =  fileDateFormat;
  +    }
  +
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -1072,7 +1093,9 @@
           timeFormatter = new SimpleDateFormat("HH:mm:ss");
           timeFormatter.setTimeZone(tz);
           currentDate = new Date(System.currentTimeMillis());
  -        fileDateFormatter = new SimpleDateFormat("yyyy-MM-dd");
  +        if (fileDateFormat==null || fileDateFormat.length()==0)
  +            fileDateFormat = "yyyy-MM-dd";
  +        fileDateFormatter = new SimpleDateFormat(fileDateFormat);
           dateStamp = fileDateFormatter.format(currentDate);
           timeTakenFormatter = new DecimalFormat("0.000");
   
  
  
  
  1.4       +117 -21   
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java
  
  Index: AccessLogValve.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/valves/AccessLogValve.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AccessLogValve.java       11 Jan 2003 05:12:48 -0000      1.3
  +++ AccessLogValve.java       4 Jun 2003 16:58:21 -0000       1.4
  @@ -67,6 +67,7 @@
   import java.io.PrintWriter;
   import java.net.InetAddress;
   import java.text.SimpleDateFormat;
  +import java.text.DecimalFormat;
   import java.util.Date;
   import java.util.TimeZone;
   import javax.servlet.ServletException;
  @@ -113,18 +114,19 @@
    *     an empty string
    * <li><b>%r</b> - First line of the request
    * <li><b>%s</b> - HTTP status code of the response
  - * <li><b>%S</b> - User session ID 
  + * <li><b>%S</b> - User session ID
    * <li><b>%t</b> - Date and time, in Common Log Format format
    * <li><b>%u</b> - Remote user that was authenticated
    * <li><b>%U</b> - Requested URL path
    * <li><b>%v</b> - Local server name
    * <li><b>%D</b> - Time taken to process the request, in millis
  -  * </ul>
  + * <li><b>%T</b> - Time taken to process the request, in seconds
  + * </ul>
    * <p>In addition, the caller can specify one of the following aliases for
    * commonly utilized patterns:</p>
    * <ul>
    * <li><b>common</b> - <code>%h %l %u %t "%r" %s %b</code>
  - * <li><b>combined</b> - 
  + * <li><b>combined</b> -
    *   <code>%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"</code>
    * </ul>
    *
  @@ -140,6 +142,13 @@
    * </ul>
    * </p>
    *
  + * <p>
  + * Conditional logging is also supported. This can be done with the
  + * <code>condition</code> property.
  + * If the value returned from ServletRequest.getAttribute(condition)
  + * yields a non-null value. The logging will be skipped.
  + * </p>
  + *
    * @author Craig R. McClanahan
    * @author Jason Brittain
    * @version $Revision$ $Date$
  @@ -227,12 +236,12 @@
        * The prefix that is added to log file filenames.
        */
       private String prefix = "access_log.";
  -    
  +
   
       /**
        * Should we rotate our log file? Default is true (like old behavior)
        */
  -    private boolean rotatable = true;    
  +    private boolean rotatable = true;
   
   
       /**
  @@ -282,6 +291,12 @@
   
   
       /**
  +     * Time taken formatter for 3 decimal places.
  +     */
  +     private DecimalFormat timeTakenFormatter = null;
  +
  +
  +    /**
        * A date formatter to format a Date into a year string in the format
        * "yyyy".
        */
  @@ -326,6 +341,17 @@
       private long rotationLastChecked = 0L;
   
   
  +    /**
  +     * Are we doing conditional logging. default false.
  +     */
  +    private String condition = null;
  +
  +
  +    /**
  +     * Date format to place in log file name. Use at your own risk!
  +     */
  +    private String fileDateFormat = null;
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -425,21 +451,21 @@
        * Should we rotate the logs
        */
       public boolean isRotatable() {
  - 
  +
           return rotatable;
  - 
  +
       }
  - 
  - 
  +
  +
       /**
        * Set the value is we should we rotate the logs
        *
        * @param rotatable true is we should rotate.
        */
       public void setRotatable(boolean rotatable) {
  - 
  +
           this.rotatable = rotatable;
  - 
  +
       }
   
   
  @@ -487,6 +513,45 @@
       }
   
   
  +    /**
  +     * Return whether the attribute name to look for when
  +     * performing conditional loggging. If null, every
  +     * request is logged.
  +     */
  +    public String getCondition() {
  +
  +        return condition;
  +
  +    }
  +
  +
  +    /**
  +     * Set the ServletRequest.attribute to look for to perform
  +     * conditional logging. Set to null to log everything.
  +     *
  +     * @param condition Set to null to log everything
  +     */
  +    public void setCondition(String condition) {
  +
  +        this.condition = condition;
  +
  +    }
  +
  +    /**
  +     *  Return the date format date based log rotation.
  +     */
  +    public String getFileDateFormat() {
  +        return fileDateFormat;
  +    }
  +
  +
  +    /**
  +     *  Set the date format date based log rotation.
  +     */
  +    public void setFileDateFormat(String fileDateFormat) {
  +        this.fileDateFormat =  fileDateFormat;
  +    }
  +
       // --------------------------------------------------------- Public Methods
   
   
  @@ -514,6 +579,12 @@
           long t2=System.currentTimeMillis();
           long time=t2-t1;
   
  +        if (condition!=null &&
  +                null!=request.getRequest().getAttribute(condition)) {
  +            return;
  +        }
  +
  +
           Date date = getDate();
           StringBuffer result = new StringBuffer();
   
  @@ -688,7 +759,7 @@
                               close();
                               dateStamp = tsDate;
                               open();
  -                        }                        
  +                        }
                       }
                   }
   
  @@ -743,7 +814,7 @@
               } else {
                   pathname = dir.getAbsolutePath() + File.separator +
                               prefix + suffix;
  -            }    
  +            }
               writer = new PrintWriter(new FileWriter(pathname, true), true);
           } catch (IOException e) {
               writer = null;
  @@ -782,7 +853,7 @@
                   value = InetAddress.getLocalHost().getHostAddress();
               } catch(Throwable e){
                   value = "127.0.0.1";
  -            }    
  +            }
           } else if (pattern == 'b') {
               int length = response.getContentCount();
               if (length <= 0)
  @@ -856,6 +927,8 @@
               temp.append(timeZone);                              // Timezone
               temp.append(']');
               value = temp.toString();
  +        } else if (pattern == 'T') {
  +            value = timeTakenFormatter.format(time/1000d);
           } else if (pattern == 'u') {
               if (hreq != null)
                   value = hreq.getRemoteUser();
  @@ -971,6 +1044,28 @@
       }
   
   
  +    private String calculateTimeZoneOffset(long offset) {
  +        StringBuffer tz = new StringBuffer();
  +        if ((offset<0))  {
  +            tz.append("-");
  +            offset = -offset;
  +        }
  +
  +        long hourOffset = offset/(1000*60*60);
  +        long minuteOffset = (offset/(1000*60)) % 60;
  +
  +        if (hourOffset<10)
  +            tz.append("0");
  +        tz.append(hourOffset);
  +
  +        if (minuteOffset<10)
  +            tz.append("0");
  +        tz.append(minuteOffset);
  +
  +        return tz.toString();
  +    }
  +
  +
       // ------------------------------------------------------ Lifecycle Methods
   
   
  @@ -987,7 +1082,7 @@
   
   
       /**
  -     * Get the lifecycle listeners associated with this lifecycle. If this 
  +     * Get the lifecycle listeners associated with this lifecycle. If this
        * Lifecycle has no listeners registered, a zero-length array is returned.
        */
       public LifecycleListener[] findLifecycleListeners() {
  @@ -1028,11 +1123,11 @@
   
           // Initialize the timeZone, Date formatters, and currentDate
           TimeZone tz = TimeZone.getDefault();
  -        timeZone = "" + (tz.getRawOffset() / (60 * 60 * 10));
  -        if (timeZone.length() < 5)
  -            timeZone = timeZone.substring(0, 1) + "0" +
  -                timeZone.substring(1, timeZone.length());
  -        dateFormatter = new SimpleDateFormat("yyyy-MM-dd");
  +        timeZone = calculateTimeZoneOffset(tz.getRawOffset());
  +
  +        if (fileDateFormat==null || fileDateFormat.length()==0)
  +            fileDateFormat = "yyyy-MM-dd";
  +        dateFormatter = new SimpleDateFormat(fileDateFormat);
           dateFormatter.setTimeZone(tz);
           dayFormatter = new SimpleDateFormat("dd");
           dayFormatter.setTimeZone(tz);
  @@ -1044,6 +1139,7 @@
           timeFormatter.setTimeZone(tz);
           currentDate = new Date();
           dateStamp = dateFormatter.format(currentDate);
  +        timeTakenFormatter = new DecimalFormat("0.000");
   
           open();
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to