Class PEAccessLogValve

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

    public final class PEAccessLogValve
    extends ValveBase
    implements Runnable

    Implementation of the Valve interface that generates a web server access log with the detailed line contents matching a configurable pattern. The syntax of the available patterns is similar to that supported by the Apache mod_log_config module. As an additional feature, automatic rollover of log files at a specified interval is also supported.

    This class uses a direct ByteBuffer to store and write logs.
    Author:
    Jean-Francois Arcand, Charlie J. Hunt
    • Constructor Detail

      • PEAccessLogValve

        public PEAccessLogValve()
    • Method Detail

      • getWriterInterval

        public int getWriterInterval()
        Return writerThread interval (seconds)
      • setWriterInterval

        public void setWriterInterval​(int t)
        Set writerthread interval (seconds)
        Parameters:
        t -
      • geRotationInterval

        public int geRotationInterval()
        Return rotation interval
        Returns:
      • setRotationInterval

        public void setRotationInterval​(int t)
        Set rotation interval
      • setBufferSize

        public void setBufferSize​(int size)
        Set the direct ByteBuffer size
        Parameters:
        size -
      • getBufferSize

        public int getBufferSize()
        Return the direct ByteBuffer size
      • setAddDateStampToFirstAccessLogFile

        public void setAddDateStampToFirstAccessLogFile​(boolean add)
        Are we supposed to add datestamp to first access log file we create, or only starting with first rotation?
      • getDirectory

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

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

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

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

        public void setPrefix​(String p)
        Set the log file prefix.
        Parameters:
        p - prefix The new log file prefix
      • isRotatable

        public boolean isRotatable()
        Should we rotate the logs
        Returns:
      • setRotatable

        public void setRotatable​(boolean rotatable)
        Set the value is we should we rotate the logs
        Parameters:
        rotatable - true is we should rotate.
      • isRotationOnDateChange

        public boolean isRotationOnDateChange()
      • setRotationOnDateChange

        public void setRotationOnDateChange​(boolean rotationOnDateChange)
      • getSuffix

        public String getSuffix()
        Return the log file suffix.
        Returns:
      • setSuffix

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

        public void setResolveHosts​(boolean resolveHosts)
        Set the resolve hosts flag.
        Parameters:
        resolveHosts - The new resolve hosts value
      • isResolveHosts

        public boolean isResolveHosts()
        Get the value of the resolve hosts flag.
      • getCondition

        public String getCondition()
        Return whether the attribute name to look for when performing conditional loggging. If null, every request is logged.
        Returns:
      • 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
      • getFileDateFormat

        public String getFileDateFormat()
        Return the date format date based log rotation.
        Returns:
      • setFileDateFormat

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

        public int invoke​(Request request,
                          Response response)
        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:
      • postInvoke

        public void postInvoke​(Request request,
                               Response response)
                        throws IOException
        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
      • log

        public void log()
                 throws IOException
        Log the specified message to the log file, switching files if the date has changed since the previous log call.
        Throws:
        IOException
      • 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
      • run

        public void run()
        The background writerThread that checks for write the log.
        Specified by:
        run in interface Runnable