Class ExtendedAccessLogValve

  • All Implemented Interfaces:
    Contained, Lifecycle, Valve, GlassFishValve

    public final class ExtendedAccessLogValve
    extends ValveBase
    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 checkExistsis 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.4 $ $Date: 2006/04/17 16:44:48 $
    Author:
    Tim Funk
    • Constructor Detail

      • ExtendedAccessLogValve

        public ExtendedAccessLogValve()
        Construct a new instance of this class with default property values.
    • Method Detail

      • getDirectory

        public String getDirectory()
        Return the directory in which we create log files.
      • setDirectory

        public void setDirectory​(String directory)
        Set the directory in which we create log files.
        Parameters:
        directory - The new log file directory
      • getPattern

        public String getPattern()
        Return the format pattern.
      • setPattern

        public void setPattern​(String pattern)
        Set the format pattern, first translating any recognized alias.
        Parameters:
        pattern - The new pattern pattern
      • getPrefix

        public String getPrefix()
        Return the log file prefix.
      • setPrefix

        public void setPrefix​(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 String getSuffix()
        Return the log file suffix.
      • setSuffix

        public void setSuffix​(String suffix)
        Set the log file suffix.
        Parameters:
        suffix - The new log file suffix
      • getCondition

        public String getCondition()
        Return whether the attribute name to look for when performing conditional loggging. If null, every request is logged.
      • setCondition

        public void setCondition​(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 String getFileDateFormat()
        Return the date format date based log rotation.
      • setFileDateFormat

        public void setFileDateFormat​(String fileDateFormat)
        Set the date format date based log rotation.
      • invoke

        public int invoke​(Request request,
                          Response response)
                   throws IOException,
                          jakarta.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 GlassFishValve
        Specified by:
        invoke in class ValveBase
        Parameters:
        request - Request being processed
        response - Response being processed
        Returns:
        INVOKE_NEXT or END_PIPELINE
        Throws:
        IOException - if an input/output error has occurred
        jakarta.servlet.ServletException - if a servlet error has occurred
      • postInvoke

        public void postInvoke​(Request request,
                               Response response)
                        throws IOException,
                               jakarta.servlet.ServletException
        Description copied from class: ValveBase
        A post-request processing implementation that does nothing. Very few Valves override this behaviour as most Valve logic is used for request processing.
        Specified by:
        postInvoke in interface GlassFishValve
        Overrides:
        postInvoke in class ValveBase
        Parameters:
        request - The servlet request to be processed
        response - The servlet response to be created
        Throws:
        IOException - if an input/output error occurs
        jakarta.servlet.ServletException - if a servlet error occurs
      • rotate

        public boolean rotate​(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
      • 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
        Overrides:
        start in class ValveBase
        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
        Overrides:
        stop in class ValveBase
        Throws:
        LifecycleException - if this component detects a fatal error that needs to be reported
      • decodePattern

        public org.apache.catalina.valves.FieldInfo[] decodePattern​(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