## org.apache.catalina.valves
Class ExtendedAccessLogValve

    java.lang.Object
      org.apache.catalina.valves.ValveBase
          org.apache.catalina.valves.ExtendedAccessLogValve

All Implemented Interfaces:
  Contained, Lifecycle, javax.management.MBeanRegistration, Valve

public final class ExtendedAccessLogValve
extends ValveBase
implements Lifecycle

An implementation of the W3c Extended Log File Format. See http://www.w3.org/TR/WD-logfile.html for more information about the format. The following fields are supported:

- `c-dns`: Client hostname
- `c-ip`: Client ip address
- `bytes`: bytes served
- `cs-method`: request method
- `cs-uri`: The full uri requested
- `cs-uri-query`: The query string
- `cs-uri-stem`: The uri without query string
- `date`: The date in yyyy-mm-dd format for GMT
- `s-dns`: The server dns entry
- `s-ip`: The server ip address
- `cs(XXX)`: The value of header XXX from client to server
- `sc(XXX)`: The value of header XXX from server to client
- `sc-status`: The status code
- `time`: Time the request was served
- `time-taken`: Time (in seconds) taken to serve the request
- `x-A(XXX)`: Pull XXX attribute from the servlet context
- `x-C(XXX)`: Pull the first cookie of the name XXX
- `x-R(XXX)`: Pull XXX attribute from the servlet request
- `x-S(XXX)`: Pull XXX attribute from the session
- `x-P(...)`: Call request.getParameter(...) and URLencode it. Helpful to capture certain POST parameters.
- For any of the x-H(...) the following method will be called from the HttpServletRequestObject
- `x-H(authType)`: getAuthType
- `x-H(characterEncoding)`: getCharacterEncoding
- `x-H(contentLength)`: getContentLength
- `x-H(locale)`: getLocale
- `x-H(protocol)`: getProtocol
- `x-H(remoteUser)`: getRemoteUser
- `x-H(requestedSessionId)`: getGequestedSessionId
- `x-H(requestedSessionIdFromCookie)`: isRequestedSessionIdFromCookie
- `x-H(requestedSessionIdValid)`: isRequestedSessionIdValid
- `x-H(scheme)`: getScheme
- `x-H(secure)`: isSecure

Log rotation can be on or off. This is dictated by the rotatable property.

For UNIX users, another field called `checkExists`is also available. If set to true, the log file's existence will be checked before each logging. This way an external log rotator can move the file somewhere and tomcat will start with a new file.

For JMX junkies, a public method called rotate has been made available to allow you to tell this instance to move the existing log file to somewhere else start writing a new log file.

Conditional logging is also supported. This can be done with the `condition` property. If the value returned from ServletRequest.getAttribute(condition) yields a non-null value. The logging will be skipped.

For extended attributes coming from a getAttribute() call, it is you responsibility to ensure there are no newline or control characters.

Version:
  $Revision: 1.8.2.1 $ $Date: 2004/08/21 15:49:56 $
Author:
  Tim Funk

Field Summary
`protected static java.lang.String` `info` The descriptive information about this implementation.
`protected LifecycleSupport` `lifecycle` The lifecycle event support for this component.

Fields inherited from class org.apache.catalina.valves.ValveBase
`container, controller, debug, domain, mserver, oname`

Fields inherited from interface org.apache.catalina.Lifecycle
`AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, START_EVENT, STOP_EVENT`

Constructor Summary
`ExtendedAccessLogValve()` Construct a new instance of this class with default property values.

Method Summary
`void` `addLifecycleListener(LifecycleListener listener)` Add a lifecycle event listener to this component.
`org.apache.catalina.valves.FieldInfo[]` `decodePattern(java.lang.String fields)` Decode the given pattern.
`LifecycleListener[]` `findLifecycleListeners()` Get the lifecycle listeners associated with this lifecycle.
`java.lang.String` `getCondition()` Return whether the attribute name to look for when performing conditional loggging.
`java.lang.String` `getDirectory()` Return the directory in which we create log files.
`java.lang.String` `getFileDateFormat()` Return the date format date based log rotation.
`java.lang.String` `getInfo()` Return descriptive information about this implementation.
`java.lang.String` `getPattern()` Return the format pattern.
`java.lang.String` `getPrefix()` Return the log file prefix.
`java.lang.String` `getSuffix()` Return the log file suffix.
`void` `invoke(Request request, Response response, ValveContext context)` Log a message summarizing the specified request and response, according to the format specified by the `pattern` property.
`boolean` `isCheckExists()` Check for file existence before logging.
`boolean` `isRotatable()` Return true if logs are automatically rotated.
`void` `removeLifecycleListener(LifecycleListener listener)` Remove a lifecycle event listener from this component.
`boolean` `rotate(java.lang.String newFileName)` Rename the existing log file to something else.
`void` `setCheckExists(boolean checkExists)` Set whether to check for log file existence before logging.
`void` `setCondition(java.lang.String condition)` Set the ServletRequest.attribute to look for to perform conditional logging.
`void` `setDirectory(java.lang.String directory)` Set the directory in which we create log files.
`void` `setFileDateFormat(java.lang.String fileDateFormat)` Set the date format date based log rotation.
`void` `setPattern(java.lang.String pattern)` Set the format pattern, first translating any recognized alias.
`void` `setPrefix(java.lang.String prefix)` Set the log file prefix.
`void` `setRotatable(boolean rotatable)` Set the value is we should we rotate the logs
`void` `setSuffix(java.lang.String suffix)` Set the log file suffix.
`void` `start()` Prepare for the beginning of active use of the public methods of this component.
`void` `stop()` Gracefully terminate the active use of the public methods of this component.

Methods inherited from class org.apache.catalina.valves.ValveBase
`createObjectName, getContainer, getContainerName, getController, getDebug, getDomain, getObjectName, getParentName, postDeregister, postRegister, preDeregister, preRegister, setContainer, setController, setDebug, setObjectName`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### info

    protected static final java.lang.String info

  The descriptive information about this implementation.

  See Also:
    Constant Field Values

### lifecycle

    protected LifecycleSupport lifecycle

  The lifecycle event support for this component.

Constructor Detail

### ExtendedAccessLogValve

    public ExtendedAccessLogValve()

  Construct a new instance of this class with default property values.

Method Detail

### getDirectory

    public java.lang.String getDirectory()

  Return the directory in which we create log files.

### setDirectory

    public void setDirectory(java.lang.String directory)

  Set the directory in which we create log files.

  Parameters:
    `directory` - The new log file directory

### getInfo

    public java.lang.String getInfo()

  Return descriptive information about this implementation.

  Specified by:
    `getInfo` in interface `Valve`
  Overrides:
    `getInfo` in class `ValveBase`

### getPattern

    public java.lang.String getPattern()

  Return the format pattern.

### setPattern

    public void setPattern(java.lang.String pattern)

  Set the format pattern, first translating any recognized alias.

  Parameters:
    `pattern` - The new pattern pattern

### getPrefix

    public java.lang.String getPrefix()

  Return the log file prefix.

### setPrefix

    public void setPrefix(java.lang.String prefix)

  Set the log file prefix.

  Parameters:
    `prefix` - The new log file prefix

### isRotatable

    public boolean isRotatable()

  Return true if logs are automatically rotated.

### setRotatable

    public void setRotatable(boolean rotatable)

  Set the value is we should we rotate the logs

  Parameters:
    `rotatable` - true is we should rotate.

### getSuffix

    public java.lang.String getSuffix()

  Return the log file suffix.

### setSuffix

    public void setSuffix(java.lang.String suffix)

  Set the log file suffix.

  Parameters:
    `suffix` - The new log file suffix

### getCondition

    public java.lang.String getCondition()

  Return whether the attribute name to look for when performing conditional loggging. If null, every request is logged.

### setCondition

    public void setCondition(java.lang.String condition)

  Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.

  Parameters:
    `condition` - Set to null to log everything

### isCheckExists

    public boolean isCheckExists()

  Check for file existence before logging.

### setCheckExists

    public void setCheckExists(boolean checkExists)

  Set whether to check for log file existence before logging.

  Parameters:
    `checkExists` - true meaning to check for file existence.

### getFileDateFormat

    public java.lang.String getFileDateFormat()

  Return the date format date based log rotation.

### setFileDateFormat

    public void setFileDateFormat(java.lang.String fileDateFormat)

  Set the date format date based log rotation.

### invoke

    public void invoke(Request request,
                       Response response,
                       ValveContext context)
                throws java.io.IOException,
                       javax.servlet.ServletException

  Log a message summarizing the specified request and response, according to the format specified by the `pattern` property.

  Specified by:
    `invoke` in interface `Valve`
  Specified by:
    `invoke` in class `ValveBase`
  Parameters:
    `request` - Request being processed
    `response` - Response being processed
    `context` - The valve context used to invoke the next valve in the current processing pipeline
  Throws:
    `java.io.IOException` - if an input/output error has occurred
    `javax.servlet.ServletException` - if a servlet error has occurred

### rotate

    public boolean rotate(java.lang.String newFileName)

  Rename the existing log file to something else. Then open the old log file name up once again. Intended to be called by a JMX agent.

  Parameters:
    `newFileName` - The file name to move the log file entry to
  Returns:
    true if a file was rotated with no error

### addLifecycleListener

    public void addLifecycleListener(LifecycleListener listener)

  Add a lifecycle event listener to this component.

  Specified by:
    `addLifecycleListener` in interface `Lifecycle`
  Parameters:
    `listener` - The listener to add

### findLifecycleListeners

    public LifecycleListener[] findLifecycleListeners()

  Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.

  Specified by:
    `findLifecycleListeners` in interface `Lifecycle`

### removeLifecycleListener

    public void removeLifecycleListener(LifecycleListener listener)

  Remove a lifecycle event listener from this component.

  Specified by:
    `removeLifecycleListener` in interface `Lifecycle`
  Parameters:
    `listener` - The listener to add

### start

    public void start()
               throws LifecycleException

  Prepare for the beginning of active use of the public methods of this component. This method should be called after `configure()`, and before any of the public methods of the component are utilized.

  Specified by:
    `start` in interface `Lifecycle`
  Throws:
    `LifecycleException` - if this component detects a fatal error that prevents this component from being used

### stop

    public void stop()
              throws LifecycleException

  Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.

  Specified by:
    `stop` in interface `Lifecycle`
  Throws:
    `LifecycleException` - if this component detects a fatal error that needs to be reported

### decodePattern

    public org.apache.catalina.valves.FieldInfo[] decodePattern(java.lang.String fields)

  Decode the given pattern. Is public so a pattern may allows to be validated.

  Parameters:
    `fields` - The pattern to decode
  Returns:
    null on error. Otherwise array of decoded fields

Copyright © 2000-2003 Apache Software Foundation. All Rights Reserved.