org.w3c.jigsaw.filters
Class LogFilter

java.lang.Object
  extended by org.w3c.tools.resources.AttributeHolder
      extended by org.w3c.tools.resources.Resource
          extended by org.w3c.tools.resources.FramedResource
              extended by org.w3c.tools.resources.ResourceFrame
                  extended by org.w3c.tools.resources.ResourceFilter
                      extended by org.w3c.jigsaw.filters.LogFilter
All Implemented Interfaces:
java.lang.Cloneable, java.util.EventListener, AttributeChangedListener, FrameEventListener, FilterInterface

public class LogFilter
extends ResourceFilter

This filter provides a very flexible logger. It is not designed as a logger, in order to be plugable only on a sub-tree of the URL space (a logger would log all site accesses). It provides as much details as you want, and uses a very simple format: each log entry (or record is made of several lines having the folowing format:

variable=value
A record starts with the special url variable value which provides the requested URL. The for each header that is to be logged, a variable is added in the record, prefixed by its scope. The scope can be either:
request
to specify a request header,
reply
to specify a reply header,
server
to specify global server samples.
As an example, if you configure that filter to log the request's referer and the reply content length, a sample record will look like:
 url=http://www.w3.org/pub/WWW/Jigsaw/
 request.referer=http://www.w3.org/pub/WWW
 reply.content-length=10
 


Field Summary
protected static int ATTR_LOGFILE
          Attribute index - The log file to use to emit log record.
protected static int ATTR_REPLY_HEADERS
          Attribute index - The HTTP reply headers to dump
protected static int ATTR_REQUEST_HEADERS
          Attribute index - The HTTP request headers to dump
static java.lang.String DONT_LOG
          Name of the state that when set on the request will prevent logging.
protected  java.io.RandomAccessFile log
          Open log descriptor, to write to the log.
protected  HeaderDescription[] repheaders
          Compiled index of the reply headers to dump.
protected  HeaderDescription[] reqheaders
          Compiled index of the request headers to dump.
 
Fields inherited from class org.w3c.tools.resources.ResourceFrame
filterClass, frameListener, resource
 
Fields inherited from class org.w3c.tools.resources.FramedResource
ATTR_OID, attrListener, debugEvent, event_disabled, framesRef, structListener
 
Fields inherited from class org.w3c.tools.resources.Resource
ATTR_CONTEXT, ATTR_HELP_URL, ATTR_IDENTIFIER, ATTR_LAST_MODIFIED, ATTR_PARENT, ATTR_RESOURCE_FRAMES, ATTR_STORE_ENTRY, ATTR_URL, co, id
 
Fields inherited from class org.w3c.tools.resources.AttributeHolder
attributes, values
 
Constructor Summary
LogFilter()
           
 
Method Summary
protected  HeaderDescription[] compileHeaders(HttpMessage kind, java.lang.String[] headers)
          Compile the given set of header names into header indexes.
 java.io.File getLogfile()
          Get the log file.
 java.lang.String[] getReplyHeaders()
          Get the list of reply headers to dump.
 java.lang.String[] getRequestHeaders()
          Get the list of request headers to dump.
 void initialize(java.lang.Object[] values)
          Initialize the filter.
protected  void log(Request request, Reply reply)
          Log the given request/reply transaction.
protected  void openLog()
          Open the log stream, and make it available through log.
 ReplyInterface outgoingFilter(RequestInterface req, ReplyInterface rep)
          Log the request.
 void setValue(int idx, java.lang.Object value)
          Traop setValue calls.
protected  void writelog(java.lang.String record)
          Write the given string to the log file.
 
Methods inherited from class org.w3c.tools.resources.ResourceFilter
exceptionFilter, getTargetResource, ingoingFilter, ingoingFilter, initialize, lookup, outgoingFilter, outputFilter, pickleValues
 
Methods inherited from class org.w3c.tools.resources.ResourceFrame
addFrameEventListener, attributeChanged, checkRequest, eventDisabled, fireFrameEvent, frameModified, getFilters, getFilters, getFrameReference, getResource, getResourceReference, getSpaceEntry, getURLPath, lookupFilters, lookupFrames, perform, postFrameEvent, processEvent, registerResource, removeFrameEventListener, unregisterResource, updateDefaultChildAttributes
 
Methods inherited from class org.w3c.tools.resources.FramedResource
addAttributeChangedListener, addStructureChangedListener, collectFramesReference, delete, disableEvent, displayEvent, enableEvent, fireAttributeChangeEvent, fireStructureChangedEvent, fireStructureChangedEvent, frameAdded, frameRemoved, getClone, getFrame, getFrame, getFrameReference, getFrameReference, getFramesReference, getOid, markModified, notifyUnload, performFrames, postAttributeChangeEvent, postEvent, postStructureChangedEvent, postStructureChangedEvent, registerFrame, registerFrameIfNone, removeAttributeChangedListener, removeStructureChangedListener, setSilentValue, setSilentValue, unregisterFrame
 
Methods inherited from class org.w3c.tools.resources.Resource
acceptUnload, checkMultipleLock, collectFrames, getContext, getFrame, getFrames, getHelpURL, getHelpURL, getIdentifier, getLastModified, getParent, getServer, getSpace, getStoreEntry, getValue, getValue, isInitialized, isUnloaded, setContext, setContext, setValue, unsafeGetContext, unsafeGetFrame, unsafeGetFrames, unsafeGetIdentifier, unsafeGetResourceReference, unsafeGetURLPath, unsafeGetValue, updateAttributes
 
Methods inherited from class org.w3c.tools.resources.AttributeHolder
definesAttribute, definesAttribute, getAttributes, getBoolean, getChar, getClone, getClone, getDouble, getFloat, getInt, getLong, getString, getValue, lookupAttribute, print, setBoolean, setChar, setDouble, setFloat, setInt, setLong, setString, setValue, unsafeDefinesAttribute, unsafeGetDouble, unsafeGetString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DONT_LOG

public static final java.lang.String DONT_LOG
Name of the state that when set on the request will prevent logging.

See Also:
Constant Field Values

ATTR_REQUEST_HEADERS

protected static int ATTR_REQUEST_HEADERS
Attribute index - The HTTP request headers to dump


ATTR_REPLY_HEADERS

protected static int ATTR_REPLY_HEADERS
Attribute index - The HTTP reply headers to dump


ATTR_LOGFILE

protected static int ATTR_LOGFILE
Attribute index - The log file to use to emit log record.


reqheaders

protected HeaderDescription[] reqheaders
Compiled index of the request headers to dump.


repheaders

protected HeaderDescription[] repheaders
Compiled index of the reply headers to dump.


log

protected java.io.RandomAccessFile log
Open log descriptor, to write to the log.

Constructor Detail

LogFilter

public LogFilter()
Method Detail

compileHeaders

protected HeaderDescription[] compileHeaders(HttpMessage kind,
                                             java.lang.String[] headers)
Compile the given set of header names into header indexes.

Parameters:
kind - An instance of the class whose headers are to be dumped.
headers - The name of headers to compile.
Returns:
An array of header description, which will allow fast fetch of header values.

writelog

protected void writelog(java.lang.String record)
Write the given string to the log file.

Parameters:
record - The string to write.

openLog

protected void openLog()
Open the log stream, and make it available through log. If opening the stream failed, an appropriate error message is emitted and log remains set to null. If a log stream was already opened, it is first closed.


getLogfile

public java.io.File getLogfile()
Get the log file.

Returns:
A File instance, or null if not set.

getRequestHeaders

public java.lang.String[] getRequestHeaders()
Get the list of request headers to dump.

Returns:
An array of String containing the name of headers to dump, or null if undefined.

getReplyHeaders

public java.lang.String[] getReplyHeaders()
Get the list of reply headers to dump.

Returns:
An array of String containing the name of headers to dump, or null if undefined.

setValue

public void setValue(int idx,
                     java.lang.Object value)
Traop setValue calls. We maintain a compiled version of both the request-headers and the reply-headers attributes, make sure they stay in sync even when modified.

Overrides:
setValue in class ResourceFrame
Parameters:
idx - The index of the attribute to modify.
value - The new attribute value.

log

protected void log(Request request,
                   Reply reply)
Log the given request/reply transaction. Dump a record for the given transaction.

Parameters:
request - The request to log.
reply - It's associated reply.

outgoingFilter

public ReplyInterface outgoingFilter(RequestInterface req,
                                     ReplyInterface rep)
                              throws ProtocolException
Log the request.

Overrides:
outgoingFilter in class ResourceFilter
Parameters:
request - The request that has been handled.
reply - It's associated reply.
Returns:
A Reply instance, or null if processing should continue normally.
Throws:
ProtocolException - If processing should be interrupted, because an abnormal situation occured.

initialize

public void initialize(java.lang.Object[] values)
Initialize the filter.

Overrides:
initialize in class FramedResource
Parameters:
values - Default attribute values.