Class LogService

java.lang.Object
org.restlet.service.Service
org.restlet.service.LogService

public class LogService extends Service
Service providing access logging service. The implementation is fully based on the standard logging mechanism introduced in JDK 1.4.

The default access log format follows the W3C Extended Log File Format with the following fields used:
  1. Date (YYYY-MM-DD)
  2. Time (HH:MM:SS)
  3. Client address (IP)
  4. Remote user identifier (see RFC 1413)
  5. Server address (IP)
  6. Server port
  7. Method (GET|POST|...)
  8. Resource reference path (including the leading slash)
  9. Resource reference query (excluding the leading question mark)
  10. Response status code
  11. Number of bytes sent
  12. Number of bytes received
  13. Time to serve the request (in milliseconds)
  14. Host reference
  15. Client agent name
  16. Referrer reference

If you use Analog to generate your log reports, and if you use the default log format, then you can simply specify this string as a value of the LOGFORMAT command: (%Y-%m-%d\t%h:%n:%j\t%S\t%u\t%j\t%j\t%j\t%r\t%q\t%c\t%b\t%j\t%T\t%v\t%B\t%f)

For custom access log format, see the syntax to use and the list of available variable names in Template.
Author:
Jerome Louvel
See Also:
  • Field Details

    • responseLogTemplate

      protected volatile Template responseLogTemplate
      The response log template to use.
  • Constructor Details

    • LogService

      public LogService()
      Constructor.
    • LogService

      public LogService(boolean enabled)
      Constructor.
      Parameters:
      enabled - True if the service has been enabled.
  • Method Details

    • createInboundFilter

      public Filter createInboundFilter(Context context)
      Description copied from class: Service
      Create the filter that should be invoked for incoming calls.
      Overrides:
      createInboundFilter in class Service
      Parameters:
      context - The current context.
      Returns:
      The new filter or null.
    • getDefaultResponseLogMessage

      protected String getDefaultResponseLogMessage(Response response, int duration)
      Format a log entry using the default IIS log format.
      Parameters:
      response - The response to log.
      duration - The call duration (in milliseconds).
      Returns:
      The formatted log entry.
    • getLoggableTemplate

      public Template getLoggableTemplate()
      Returns the URI template of loggable resource references. Returns null by default, meaning the all requests are loggable, independant of their target resource URI reference.
      Returns:
      The URI template of loggable resource references.
      See Also:
    • getLoggerName

      public String getLoggerName()
      Returns the name of the JDK's logger to use when logging access calls. The default name will follow this pattern: "org.restlet.MyComponent.LogService", where "MyComponent" will correspond to the simple class name of your component subclass or to the base "Component" class.
      Returns:
      The name of the JDK's logger to use when logging access calls.
    • getLogPropertiesRef

      public Reference getLogPropertiesRef()
      Returns the URI reference of the log properties.
      Returns:
      The URI reference of the log properties.
    • getResponseLogFormat

      public String getResponseLogFormat()
      Returns the format used when logging responses.
      Returns:
      The format used, or null if the default one is used.
      See Also:
    • getResponseLogMessage

      public String getResponseLogMessage(Response response, int duration)
      Format an access log entry. If the log template property isn't provided, then a default IIS like format is used.
      Parameters:
      response - The response to log.
      duration - The call duration.
      Returns:
      The formatted log entry.
    • isIdentityCheck

      public boolean isIdentityCheck()
      Indicates if the identity check (as specified by RFC1413) is enabled. Default value is false.
      Returns:
      True if the identity check is enabled.
    • isLoggable

      public boolean isLoggable(Request request)
      Indicates if the call should be logged during the processing chain. By default, it tries to match the request URI with the getLoggableTemplate() URI template otherwise is returns true.
      Parameters:
      request - The request to log.
      Returns:
      True if the call should be logged during the processing chain.
    • setIdentityCheck

      public void setIdentityCheck(boolean identityCheck)
      Indicates if the identity check (as specified by RFC1413) is enabled.
      Parameters:
      identityCheck - True if the identity check is enabled.
    • setLoggableTemplate

      public void setLoggableTemplate(String loggableTemplateRef)
      Sets the URI template of loggable resource references.
      Parameters:
      loggableTemplateRef - The URI template of loggable resource references.
      See Also:
    • setLoggableTemplate

      public void setLoggableTemplate(Template loggableTemplate)
      Sets the URI template of loggable resource references.
      Parameters:
      loggableTemplate - The URI template of loggable resource references.
    • setLoggerName

      public void setLoggerName(String name)
      Sets the name of the JDK's logger to use when logging access calls.
      Parameters:
      name - The name of the JDK's logger to use when logging access calls.
    • setLogPropertiesRef

      public void setLogPropertiesRef(Reference logPropertiesRef)
      Sets the URI reference of the log properties.
      Parameters:
      logPropertiesRef - The URI reference of the log properties.
    • setLogPropertiesRef

      public void setLogPropertiesRef(String logPropertiesUri)
      Sets the URI reference of the log properties.
      Parameters:
      logPropertiesUri - The URI reference of the log properties.
    • setResponseLogFormat

      public void setResponseLogFormat(String responseLogFormat)
      Sets the format to use when logging responses. The default format matches the one of IIS 6.
      Parameters:
      responseLogFormat - The format to use when logging responses.
      See Also:
    • start

      public void start() throws Exception
      Starts the log service by attempting to read the log properties if the getLogPropertiesRef() returns a non null URI reference.
      Overrides:
      start in class Service
      Throws:
      Exception