FileDocCategorySizeDatePackage
AccessLogFormatter.javaAPI DocGlassfish v2 API6650Fri May 04 22:36:04 BST 2007com.sun.enterprise.web.accesslog

AccessLogFormatter

public abstract class AccessLogFormatter extends Object
Abstract class defining an interface for appending access log entries to the access log in a customized access log format.

Fields Summary
protected static final String[]
months
The set of month abbreviations for log messages.
protected static final String
SPACE
When formatting log lines, we often use strings like this one (" ").
protected SimpleDateFormat
dayFormatter
A date formatter to format Dates into a day string in the format "dd".
protected SimpleDateFormat
monthFormatter
A date formatter to format a Date into a month string in the format "MM".
protected SimpleDateFormat
yearFormatter
A date formatter to format a Date into a year string in the format "yyyy".
protected SimpleDateFormat
timeFormatter
A date formatter to format a Date into a time in the format "kk:mm:ss" (kk is a 24-hour representation of the hour).
protected String
timeZone
The time zone relative to GMT.
protected TimeZone
tz
protected boolean
needTimeTaken
private Date
currentDate
The system time when we last updated the Date that this valve uses for log lines.
Constructors Summary
public AccessLogFormatter()
Constructor. Initialize the timeZone and currentDate.



               
      
        tz = TimeZone.getDefault();
        timeZone = calculateTimeZoneOffset(tz.getRawOffset());
        currentDate = new Date(System.currentTimeMillis());
    
Methods Summary
public abstract voidappendLogEntry(org.apache.catalina.Request request, org.apache.catalina.Response response, java.nio.CharBuffer charBuffer)
Appends an access log entry line, with info obtained from the given request and response objects, to the given CharBuffer.

param
request The request object from which to obtain access log info
param
response The response object from which to obtain access log info
param
charBuffer The CharBuffer to which to append access log info

protected java.lang.StringcalculateTimeZoneOffset(long offset)

        StringBuffer sb = new StringBuffer();
        if ((offset<0))  {
            sb.append("-");
            offset = -offset;
        } else {
            sb.append("+");
        }

        long hourOffset = offset/(1000*60*60);
        long minuteOffset = (offset/(1000*60)) % 60;

        if (hourOffset<10)
            sb.append("0");
        sb.append(hourOffset);

        if (minuteOffset<10)
            sb.append("0");
        sb.append(minuteOffset);

        return sb.toString();
    
protected synchronized java.util.DategetDate()
This method returns a Date object that is accurate to within one second. If a writerThread calls this method to get a Date and it's been less than 5 second since a new Date was created, this method simply gives out the same Date again so that the system doesn't spend time creating Date objects unnecessarily.


        // Only create a new Date once per second, max.
        long systime = System.currentTimeMillis();
        if ((systime - currentDate.getTime()) > 5000) {
            currentDate = new Date(systime);
        }

        return currentDate;

    
protected java.lang.Stringlookup(java.lang.String month)
Return the month abbreviation for the specified month, which must be a two-digit String.

param
month Month number ("01" .. "12").


        int index;
        try {
            index = Integer.parseInt(month) - 1;
        } catch (Throwable t) {
            index = 0;  // Can not happen, in theory
        }
        return (months[index]);

    
public booleanneedTimeTaken()
Has the time-taken token been specified in the access log pattern?

return
true if the time-taken token has been specified in the access log pattern, false otherwise.

        return needTimeTaken;